home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_lrm / chap03.doc < prev    next >
Text File  |  1996-01-30  |  149KB  |  5,810 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. The following document is a draft  of  the  corresponding  chapter  of  the
  7. version  of  the  Ada  Reference  Manual  produced  in response to the Ansi
  8. Canvass.  It is given a limited circulation  to  Ada  implementers  and  to
  9. other groups contributing comments (according to the conventions defined in
  10. RRM.comments).  This draft should not be referred to in any publication.
  11.  
  12.  
  13.  
  14.                       ANSI-RM-03-v23 - Draft Chapter
  15.  
  16.                          3  Declarations and Types
  17.                                 version 23
  18.  
  19.                                  83-02-11
  20.  
  21. This version has addressed comments up to #5795
  22.  
  23. It has not yet considered the proposed amendment #3518
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                          3. Declarations and Types
  78.  
  79.  
  80.  
  81. This  chapter  describes  the  types  in  the  language  and  the rules for
  82. declaring constants, variables, and named numbers.
  83.  
  84.  
  85.  
  86. 3.1  Declarations
  87.  
  88.  
  89. The language defines several kinds of entities that  are  declared,  either
  90. explicitly or implicitly, by declarations.  Such an entity can be a numeric
  91. literal,  an  object, a discriminant, a record component, a loop parameter,
  92. an exception, a type, a subtype, a subprogram, a package, a  task  unit,  a
  93. generic  unit,  a  single  entry, an entry family, a formal parameter (of a
  94. subprogram, entry, or generic subprogram), a generic  formal  parameter,  a
  95. named  block  or loop, a labeled statement, or an operation (in particular,
  96. an attribute or an enumeration literal;  see 3.3.3).
  97.  
  98. There are several forms of declaration.  A basic declaration is a  form  of
  99. declaration defined as follows.
  100.  
  101.     basic_declaration ::=
  102.          object_declaration     | number_declaration
  103.        | type_declaration       | subtype_declaration
  104.        | subprogram_declaration | package_declaration
  105.        | task_declaration       | generic_declaration
  106.        | exception_declaration  | generic_instantiation
  107.        | renaming_declaration   | deferred_constant_declaration
  108.  
  109. Certain  forms  of declaration always occur (explicitly) as part of a basic
  110. declaration;   these  forms  are  discriminant  specifications,   component
  111. declarations,   entry   declarations,   parameter  specifications,  generic
  112. parameter declarations, and enumeration  literal  specifications.   A  loop
  113. parameter  specification  is  a  form  of  declaration  that occurs only in
  114. certain forms of loop statement.
  115.  
  116. The remaining forms of declaration are implicit:  the name of a block,  the
  117. name  of  a  loop,  and a statement label are implicitly declared.  Certain
  118. operations are implicitly declared (see 3.3.3).
  119.  
  120. For each form of declaration the language rules define a certain region  of
  121. text  called  the  scope  of  the  declaration (see 8.2).  Several forms of
  122. declaration associate an identifier with a  declared  entity.   Within  its
  123. scope,  and  only  there,  there are places where it is possible to use the
  124. identifier to refer to the associated declared entity;   these  places  are
  125. defined  by  the visibility rules (see 8.3).  At such places the identifier
  126. is said to be a name of the entity (its simple name);  the name is said  to
  127.  
  128.  
  129.                                    3 - 1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. denote the associated entity.
  139.  
  140. Certain  forms  of  enumeration literal specification associate a character
  141. literal  with  the  corresponding  declared  entity.   Certain   forms   of
  142. declaration  associate  an  operator  symbol or some other notation with an
  143. explicitly or implicitly declared operation.
  144.  
  145. The process by which a  declaration  achieves  its  effect  is  called  the
  146. elaboration  of  the  declaration;   this  process  happens  during program
  147. execution.
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                    3 - 2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. After its elaboration, a declaration is said to be  elaborated.   Prior  to
  205. the  completion  of its elaboration (including before the elaboration), the
  206. declaration is not yet elaborated.  The elaboration of any declaration  has
  207. always  at least the effect of achieving this change of state (from not yet
  208. elaborated to elaborated).   The  phrase  "the  elaboration  has  no  other
  209. effect"  is  used  in this manual whenever this change of state is the only
  210. effect of elaboration for some form of declaration.  An elaboration process
  211. is also defined for declarative parts, declarative items,  and  compilation
  212. units (see 3.9 and 10.5).
  213.  
  214. Object,  number,  type,  and  subtype declarations are described here.  The
  215. remaining basic declarations are described in later chapters.
  216.  
  217. Note:
  218.  
  219. The syntax rules use the term identifier for the  first  occurrence  of  an
  220. identifier  in  some form of declaration;  the term simple name is used for
  221. any occurrence of an identifier that already denotes some declared  entity.
  222.  
  223. References:    attribute  4.1.4,  block  name  5.6,  block  statement  5.6,
  224. character literal 2.5, component declaration  3.7,  declarative  item  3.9,
  225. declarative  part  3.9,  deferred  constant  declaration  7.4, discriminant
  226. specification 3.7.1, elaboration 3.9, entry  declaration  9.5,  enumeration
  227. literal   specification   3.5.1,   exception   declaration   11.1,  generic
  228. declaration 12.1, generic instantiation 12.3, generic parameter declaration
  229. 12.1,  identifier  2.3,  label  5.1,  loop   name   5.5,   loop   parameter
  230. specification  5.5, loop statement 5.5, name 4.1, number declaration 3.2.2,
  231. numeric literal 2.4, object  declaration  3.2.1,  operation  3.3,  operator
  232. symbol  6.1,  package  declaration 7.1, parameter specification 6.1, record
  233. component 3.7, renaming declaration 8.5, representation clause 13.1,  scope
  234. 8.2,  simple  name  4.1,  subprogram  body 6.3, subprogram declaration 6.1,
  235. subtype declaration 3.3.2, task declaration 9.1,  type  declaration  3.3.1,
  236. visibility 8.3
  237.  
  238.  
  239.  
  240. 3.2  Objects and Named Numbers
  241.  
  242.  
  243. An  object  is  an  entity that contains (has) a value of a given type.  An
  244. object is one of the following:
  245.  
  246.   -  an object declared by an  object  declaration  or  by  a  single  task
  247.      declaration,
  248.  
  249.   -  a formal parameter of a subprogram, entry, or generic subprogram,
  250.  
  251.   -  a generic formal object,
  252.  
  253.   -  a loop parameter,
  254.  
  255.   -  an object designated by a value of an access type,
  256.  
  257.   -  a component or a slice of another object.
  258.  
  259.  
  260.  
  261.                                    3 - 3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. A  number  declaration  is  a  special  form  of  object  declaration  that
  271. associates  an  identifier  with  a  value  of  type  universal_integer  or
  272. universal_real.
  273.  
  274.     object_declaration ::=
  275.          identifier_list : [constant] subtype_indication [:= expression];
  276.        | identifier_list : [constant] constrained_array_definition [:= expression];
  277.  
  278.     number_declaration ::=
  279.          identifier_list : constant := universal_static_expression;
  280.  
  281.     identifier_list ::=  identifier {, identifier}
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                    3 - 4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. An  object  declaration  is  called  a  single  object  declaration  if its
  337. identifier list has a single identifier;  it is called  a  multiple  object
  338. declaration if the identifier list has two or more identifiers.  A multiple
  339. object  declaration is equivalent to a sequence of the corresponding number
  340. of single object declarations.   For  each  identifier  of  the  list,  the
  341. equivalent  sequence  has  a  single  object  declaration  formed  by  this
  342. identifier, followed by a colon and by whatever appears at the right of the
  343. colon in the multiple object declaration;  the equivalent  sequence  is  in
  344. the same order as the identifier list.
  345.  
  346. A  similar  equivalence  applies  also  for  the identifier lists of number
  347. declarations,   component   declarations,   discriminant    specifications,
  348. parameter   specifications,   generic   parameter  declarations,  exception
  349. declarations, and deferred constant declarations.
  350.  
  351. In the remainder of this  reference  manual,  explanations  are  given  for
  352. declarations  with a single identifier;  the corresponding explanations for
  353. declarations with several identifiers follow from  the  equivalence  stated
  354. above.
  355.  
  356. Example:
  357.  
  358.     --  the multiple object declaration
  359.  
  360.     JOHN, PAUL : PERSON_NAME := new PERSON(SEX => M);  --  see 3.8.1
  361.  
  362.     --  is equivalent to the two single object declarations in the order given
  363.  
  364.     JOHN : PERSON_NAME := new PERSON(SEX => M);
  365.     PAUL : PERSON_NAME := new PERSON(SEX => M);
  366.  
  367. References:   access  type 3.8, constrained array definition 3.6, component
  368. 3.3, declaration 3.1, deferred constant  declaration  7.4,  designate  3.8,
  369. discriminant  specification  3.7.1,  entry 9.5, exception declaration 11.1,
  370. expression 4.4, formal parameter 6.1, generic formal object 12.1.1, generic
  371. parameter declaration 12.1,  generic  unit  12,  generic  subprogram  12.1,
  372. identifier   2.3,   loop   parameter   5.5,  numeric  type  3.5,  parameter
  373. specification 6.1, scope 8.2, simple name 4.1, single task declaration 9.1,
  374. slice 4.1.2, static expression 4.9, subprogram 6, subtype indication 3.3.2,
  375. type 3.3, universal_integer type 3.5.4, universal_real type 3.5.6
  376.  
  377.  
  378.  
  379. 3.2.1  Object Declarations
  380.  
  381.  
  382. An object declaration declares an object whose type is given  either  by  a
  383. subtype  indication  or  by  a constrained array definition.  If the object
  384. declaration includes the  assignment  compound  delimiter  followed  by  an
  385. expression,  the  expression  specifies  an  initial value for the declared
  386. object;  the type of the expression must be that of the object.
  387.  
  388. The declared object is a constant if the reserved word constant appears  in
  389. the  object  declaration;   the  declaration  must then include an explicit
  390. initialization.   The  value  of  a  constant  cannot  be  modified   after
  391.  
  392.  
  393.                                    3 - 5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402. initialization.   Formal  parameters of mode in of subprograms and entries,
  403. and generic formal parameters of mode  in,  are  also  constants;   a  loop
  404. parameter  is  a constant within the corresponding loop;  a subcomponent or
  405. slice of a constant is a constant.
  406.  
  407. An object that is not a constant is called a variable (in  particular,  the
  408. object declared by an object declaration that does not include the reserved
  409. word  constant  is  a  variable).   The  only ways to change the value of a
  410. variable are either directly by  an  assignment,  or  indirectly  when  the
  411. variable  is updated (see 6.2) by a procedure or entry call statement (this
  412. action can be performed either on the variable itself, on a subcomponent of
  413. the variable, or on  another  variable  that  has  the  given  variable  as
  414. subcomponent).
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                    3 - 6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. The elaboration of an object declaration proceeds as follows:
  470.  
  471. (a)  The subtype indication or the constrained array  definition  is  first
  472.      elaborated.  This establishes the subtype of the object.
  473.  
  474. (b)  If the object declaration includes  an  explicit  initialization,  the
  475.      initial value  is obtained by evaluating the corresponding expression.
  476.      Otherwise  any  implicit  initial  values  for  the  object or for its
  477.      subcomponents are evaluated.
  478.  
  479. (c)  The object is created.
  480.  
  481. (d)  Any initial value (whether explicit or implicit) is  assigned  to  the
  482.      object or to the corresponding subcomponent.
  483.  
  484. Implicit  initial  values  are  defined  for  objects  declared  by  object
  485. declarations, and for components of such objects, in the  following  cases:
  486.  
  487.   -  If the type of an object is an access type, the implicit initial value
  488.      is the null value of the access type.
  489.  
  490.   -  If the type of an object is a task type,  the  implicit  initial  (and
  491.      only) value designates a corresponding task.
  492.  
  493.   -  If the type of an object is a type with discriminants and the  subtype
  494.      of the object is constrained, the implicit initial (and only) value of
  495.      each discriminant is defined by the subtype of the object.
  496.  
  497.   -  If the type of an object is a composite  type,  the  implicit  initial
  498.      value  of  each component that has a default expression is obtained by
  499.      evaluation of this expression, unless the component is a  discriminant
  500.      of a constrained object (the previous case).
  501.  
  502. In  the  case  of  a  component that is itself a composite object and whose
  503. value is defined neither by an explicit initialization  nor  by  a  default
  504. expression,  any  implicit  initial  values for components of the composite
  505. object are defined by the same rules as for a declared object.
  506.  
  507. The steps (a) to (d) are performed in the order indicated.  For  step  (b),
  508. if  the  default  expression  for  a  discriminant  is evaluated, then this
  509. evaluation  is  performed  before   that   of   default   expressions   for
  510. subcomponents that depend on discriminants, and also before that of default
  511. expressions  that  include  the  name  of the discriminant.  Apart from the
  512. previous rule, the evaluation of default expressions is performed  in  some
  513. order that is not defined by the language.
  514.  
  515. The  initialization  of  an  object  (the  declared  object  or  one of its
  516. subcomponents) checks that the initial value belongs to the subtype of  the
  517. object;  for an array object declared by an object declaration, an implicit
  518. subtype  conversion is first applied as for an assignment statement, unless
  519. the object is a constant whose subtype is an unconstrained array type.  The
  520. exception CONSTRAINT_ERROR is raised if this check fails.
  521.  
  522.  
  523.  
  524.  
  525.                                    3 - 7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534. The value of a scalar  variable  is  undefined  after  elaboration  of  the
  535. corresponding object declaration unless an initial value is assigned to the
  536. variable by an initialization (explicitly or implicitly).
  537.  
  538. If  the  operand of a type conversion or qualified expression is a variable
  539. that has scalar subcomponents with undefined values, then the values of the
  540. corresponding subcomponents of the result are undefined.  The execution  of
  541. a  program  is erroneous if it attempts to evaluate  a scalar variable with
  542. an undefined value.  Similarly, the execution of a program is erroneous  if
  543. it  attempts to apply a predefined operator to a variable that has a scalar
  544. subcomponent with an undefined value.
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                    3 - 8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. Examples of variable declarations:
  601.  
  602.     COUNT, SUM  : INTEGER;
  603.     SIZE        : INTEGER range 0 .. 10_000 := 0;
  604.     SORTED      : BOOLEAN := FALSE;
  605.     COLOR_TABLE : array(1 .. N) of COLOR;
  606.     OPTION      : BIT_VECTOR(1 .. 10) := (others => TRUE);
  607.  
  608. Examples of constant declarations:
  609.  
  610.     LIMIT     : constant INTEGER := 10_000;
  611.     LOW_LIMIT : constant INTEGER := LIMIT/10;
  612.     TOLERANCE : constant REAL := DISPERSION(1.15);
  613.  
  614. Note:
  615.  
  616. The expression  initializing  a  constant  object  need  not  be  a  static
  617. expression  (see  4.9).   In  the  above  examples, LIMIT and LOW_LIMIT are
  618. initialized with static expressions, but TOLERANCE is not if DISPERSION  is
  619. a user-defined function.
  620.  
  621. References:  access type 3.8, assignment 5.2, assignment compound delimiter
  622. 5.2,  component  3.3, composite type 3.3, constrained array definition 3.6,
  623. constrained subtype 3.3, constraint_error exception 11.1,  conversion  4.6,
  624. declaration 3.1, default expression for a discriminant 3.7, default initial
  625. value  for  an  access  type 3.8, depend on a discriminant 3.7.1, designate
  626. 3.8,  discriminant  3.3,  elaboration  3.9,  entry  9.5,  evaluation   4.5,
  627. expression  4.4,  formal parameter 6.1, generic formal parameter 12.1 12.3,
  628. generic unit 12, in some order  1.6,  limited  type  7.4.4,  mode  in  6.1,
  629. package  7,  predefined  operator  4.5,  primary  4.4,  private  type  7.4,
  630. qualified expression 4.7, reserved word 2.9, scalar type 3.5, slice  4.1.2,
  631. subcomponent 3.3, subprogram 6, subtype 3.3, subtype indication 3.3.2, task
  632. 9, task type 9.2, type 3.3, visible part 7.2
  633.  
  634.  
  635.  
  636. 3.2.2  Number Declarations
  637.  
  638.  
  639. A  number  declaration is a special form of constant declaration.  The type
  640. of  the  static  expression  given  for  the  initialization  of  a  number
  641. declaration   must  be  either  the  type  universal_integer  or  the  type
  642. universal_real.  The constant declared by a number declaration is called  a
  643. named number and has the type of the static expression.
  644.  
  645. Note:
  646.  
  647. The  rules  concerning  expressions  of  a  universal type are explained in
  648. section 4.10.  It is a consequence of these rules  that  if  every  primary
  649. contained  in  the  expression  is  of the type universal_integer, then the
  650. named number is also of this type.  Similarly, if every primary is  of  the
  651. type universal_real, then the named number is also of this type.
  652.  
  653. Examples of number declarations:
  654.  
  655.  
  656.  
  657.                                    3 - 9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.     PI            : constant := 3.14159_26536; -- a real number
  667.     TWO_PI        : constant := 2.0*PI;        -- a real number
  668.     MAX           : constant := 500;           -- an integer number
  669.     POWER_16      : constant := 2**16;         -- the integer 65_536
  670.     ONE, UN, EINS : constant := 1;             -- three different names for 1
  671.  
  672.  
  673. References:   identifier 2.3, primary 4.4, static expression 4.9, type 3.3,
  674. universal_integer type 3.5.4, universal_real  type  3.5.6,  universal  type
  675. 4.10
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                   3 - 10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. 3.3  Types and Subtypes
  733.  
  734.  
  735. A type is characterized by a set of values and a set of operations.
  736.  
  737. There exist several classes of types.  Scalar types are integer types, real
  738. types,  and  types defined by enumeration of their values;  values of these
  739. types have no components.   Array and record types are composite;  a  value
  740. of a composite type consists of component values.  An access type is a type
  741. whose  values provide access to objects.  Private types are types for which
  742. the set of possible values is well defined, but not directly  available  to
  743. the  users  of  such types.  Finally, there are task types.  (Private types
  744. are described in chapter 7, task types are  described  in  chapter  9,  the
  745. other classes of types are described in this chapter.)
  746.  
  747. Certain   record   and   private   types  have  special  components  called
  748. discriminants whose values distinguish alternative forms of values  of  one
  749. of  these  types.   If  a private type has discriminants, they are known to
  750. users of the type.  Hence a private type is only known  by  its  name,  its
  751. discriminants if any, and by the corresponding set of operations.
  752.  
  753. The  set  of possible values for an object of a given type can be subjected
  754. to a condition that is called a constraint (the case where  the  constraint
  755. imposes  no  restriction  is  also included);  a value is said to satisfy a
  756. constraint if it satisfies the corresponding condition.   A  subtype  is  a
  757. type together with a constraint;  a value is said to belong to a subtype of
  758. a  given  type if it belongs to the type and satisfies the constraint;  the
  759. given type is called the base type of the subtype.  A type is a subtype  of
  760. itself;   such  a subtype is said to be unconstrained:  it corresponds to a
  761. condition that imposes no restriction.  The base type of a type is the type
  762. itself.
  763.  
  764. The set of operations defined for a subtype of a given  type  includes  the
  765. operations that are defined for the type;  however the assignment operation
  766. to a variable having a given subtype only assigns values that belong to the
  767. subtype.   Additional  operations,  such  as  qualification (in a qualified
  768. expression), are implicitly defined by a subtype declaration.
  769.  
  770. Certain types have default initial values defined for objects of the  type;
  771. certain  other  types  have  default expressions defined for some or all of
  772. their components.  Certain operations of  types  and  subtypes  are  called
  773. attributes;   these operations are denoted by the form of name described in
  774. section 4.1.4.
  775.  
  776. The term subcomponent is used in this manual in place of the term component
  777. to indicate either a component, or a  component  of  another  component  or
  778. subcomponent.   Where  other subcomponents are excluded, the term component
  779. is used instead.
  780.  
  781. A given type must not have a subcomponent whose  type  is  the  given  type
  782. itself.
  783.  
  784. The  name  of  a  class  of types is used in this manual as a qualifier for
  785. objects and values that have a type of the class considered.  For  example,
  786. the  term "array object" is used for an object whose type is an array type;
  787.  
  788.  
  789.                                   3 - 11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798. similarly, the term "access value" is used for a value of an  access  type.
  799.  
  800. Note:
  801.  
  802. The  set of values of a subtype is a subset of the values of the base type.
  803. This subset need not be a proper subset;  it can be an empty subset.
  804.  
  805. References:  access type 3.8, array type  3.6,  assignment  5.2,  attribute
  806. 4.1.4,  component  of an array 3.6, component of a record 3.7, discriminant
  807. constraint 3.7.2, enumeration type 3.5.1, integer type 3.5.4, object 3.2.1,
  808. private type 7.4, qualified expression 4.7, real type  3.5.6,  record  type
  809. 3.7, subtype declaration 3.3.2, task type 9.1, type declaration 3.3.1
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                   3 - 12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. 3.3.1  Type Declarations
  865.  
  866.  
  867. A type declaration declares a type.
  868.  
  869.     type_declaration ::=  full_type_declaration
  870.        | incomplete_type_declaration | private_type_declaration
  871.  
  872.     full_type_declaration ::=
  873.          type identifier [discriminant_part] is type_definition;
  874.  
  875.     type_definition ::=
  876.          enumeration_type_definition | integer_type_definition
  877.        | real_type_definition        | array_type_definition
  878.        | record_type_definition      | access_type_definition
  879.        | derived_type_definition
  880.  
  881. The  elaboration  of a full type declaration consists of the elaboration of
  882. the discriminant part, if  any  (except  in  the  case  of  the  full  type
  883. declaration  for  an  incomplete  or  private type declaration), and of the
  884. elaboration of the type definition.
  885.  
  886. The types created by the  elaboration  of  distinct  type  definitions  are
  887. distinct  types.   Moreover,  the  elaboration of the type definition for a
  888. numeric or derived type creates both a base type and a subtype of the  base
  889. type;   the  same  holds for a constrained array definition (one of the two
  890. forms of array type definition).
  891.  
  892. The simple name declared by a full type declaration  denotes  the  declared
  893. type,  unless  the type declaration declares both a base type and a subtype
  894. of the base type, in which case the simple name denotes  the  subtype,  and
  895. the  base  type  is anonymous.  A type is said to be anonymous if it has no
  896. simple name.  For explanatory purposes,  this  reference  manual  sometimes
  897. refers  to an anonymous type by a pseudo-name, written in italics, and uses
  898. such  pseudo-names  at  places  where  the  syntax  normally  requires   an
  899. identifier.
  900.  
  901. Examples of type definitions:
  902.  
  903.     (WHITE, RED, YELLOW, GREEN, BLUE, BROWN, BLACK)
  904.     range1 .. 72
  905.     array(1 .. 10) of INTEGER
  906.  
  907. Examples of type declarations:
  908.  
  909.     type COLOR  is (WHITE, RED, YELLOW, GREEN, BLUE, BROWN, BLACK);
  910.     type COLUMN is range 1 .. 72;
  911.     type TABLE  is array(1 .. 10) of INTEGER;
  912.  
  913. Notes:
  914.  
  915. Two  type  definitions  always  define two distinct types, even if they are
  916. textually identical.   Thus,  the  array  type  definitions  given  in  the
  917. declarations of A and B below define distinct types.
  918.  
  919.  
  920.  
  921.                                   3 - 13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.     A : array(1 .. 10) of BOOLEAN;
  931.     B : array(1 .. 10) of BOOLEAN;
  932.  
  933. If  A  and  B are declared by a multiple object declaration as below, their
  934. types are nevertheless different, since the multiple object declaration  is
  935. equivalent to the above two single object declarations.
  936.  
  937.     A, B : array(1 .. 10) of BOOLEAN;
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                   3 - 14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996. Incomplete  type  declarations are used for the definition of recursive and
  997. mutually dependent types (see 3.8.1).  Private type declarations  are  used
  998. in  package  specifications  and in generic parameter declarations (see 7.4
  999. and 12.1).
  1000.  
  1001. References:  access type definition 3.8, array type  definition  3.6,  base
  1002. type  3.3,  constrained  array  definition  3.6,  constrained  subtype 3.3,
  1003. declaration  3.1,  derived  type  3.4,   derived   type   definition   3.4,
  1004. discriminant  part  3.7.1,  elaboration  3.9,  enumeration  type definition
  1005. 3.5.1, identifier 2.3, incomplete  type  declaration  3.8.1,  integer  type
  1006. definition  3.5.4,  multiple  object  declaration  3.2,  numeric  type 3.5,
  1007. private type declaration 7.4, real type  definition  3.5.6,  reserved  word
  1008. 2.9, type 3.3
  1009.  
  1010.  
  1011.  
  1012. 3.3.2  Subtype Declarations
  1013.  
  1014.  
  1015. A subtype declaration declares a subtype.
  1016.  
  1017.     subtype_declaration ::=
  1018.        subtype identifier is subtype_indication;
  1019.  
  1020.     subtype_indication ::=  type_mark [constraint]
  1021.  
  1022.     type_mark ::= type_name | subtype_name
  1023.  
  1024.     constraint ::=
  1025.          range_constraint | floating_point_constraint | fixed_point_constraint
  1026.        | index_constraint | discriminant_constraint
  1027.  
  1028. A  type  mark denotes a type or a subtype.  If a type mark is the name of a
  1029. type,  the  type  mark  denotes  this  type  and  also  the   corresponding
  1030. unconstrained subtype.  The base type of a type mark is, by definition, the
  1031. base type of the type or subtype denoted by the type mark.
  1032.  
  1033. A  subtype  indication defines a subtype of the base type of the type mark.
  1034.  
  1035. If an index constraint appears after a type mark in a  subtype  indication,
  1036. the  type mark must not already impose an index constraint.  Likewise for a
  1037. discriminant  constraint,  the  type  mark  must  not  already   impose   a
  1038. discriminant constraint.
  1039.  
  1040. The elaboration of a subtype declaration consists of the elaboration of the
  1041. subtype  indication.   The  elaboration  of  a subtype indication creates a
  1042. subtype.  If the subtype indication does  not  include  a  constraint,  the
  1043. subtype is the same as that denoted by the type mark.  The elaboration of a
  1044. subtype indication that includes a constraint proceeds as follows:
  1045.  
  1046. (a)  The constraint is first elaborated.
  1047.  
  1048. (b)  A check is then made that the constraint is compatible with  the  type
  1049.      or subtype denoted by the type mark.
  1050.  
  1051.  
  1052.  
  1053.                                   3 - 15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062. The  condition  imposed  by  a  constraint  is the condition obtained after
  1063. elaboration of the constraint.  (The rules of  constraint  elaboration  are
  1064. such  that  the expressions and  ranges of constraints are evaluated by the
  1065. elaboration of these constraints.)  The rules  defining  compatibility  are
  1066. given  for each form of constraint in the appropriate section.  These rules
  1067. are such that if a constraint  is  compatible  with  a  subtype,  then  the
  1068. condition imposed by the constraint cannot contradict any condition already
  1069. imposed  by  the  subtype on its values.  The exception CONSTRAINT_ERROR is
  1070. raised if any check of compatibility fails.
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                   3 - 16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128. Examples of subtype declarations:
  1129.  
  1130.  
  1131.     subtype RAINBOW   is COLOR range RED .. BLUE;        --  see 3.3.1
  1132.     subtype RED_BLUE  is RAINBOW;
  1133.     subtype INT       is INTEGER;
  1134.     subtype SMALL_INT is INTEGER range -10 .. 10;
  1135.     subtype UP_TO_K   is COLUMN range 1 .. K;            --  see 3.3.1
  1136.     subtype SQUARE    is MATRIX(1 .. 10, 1 .. 10);       --  see 3.6
  1137.     subtype MALE      is PERSON(SEX => M);               --  see 3.8
  1138.  
  1139. Note:
  1140.  
  1141. A subtype declaration does not define a new type.
  1142.  
  1143. References:  base  type  3.3,  compatibility  of  discriminant  constraints
  1144. 3.7.2,  compatibility  of  fixed  point constraints 3.5.9, compatibility of
  1145. floating point constraints 3.5.7, compatibility of index constraints 3.6.1,
  1146. compatibility of range constraints 3.5,  constraint_error  exception  11.1,
  1147. declaration   3.1,   discriminant   3.3,   discriminant  constraint  3.7.2,
  1148. elaboration 3.9, evaluation 4.5, expression 4.4, floating point  constraint
  1149. 3.5.7,   fixed  point  constraint  3.5.9,  index  constraint  3.6.1,  range
  1150. constraint 3.5, reserved word 2.9, subtype 3.3, type 3.3, type name  3.3.1,
  1151. unconstrained subtype 3.3
  1152.  
  1153.  
  1154.  
  1155. 3.3.3  Classification of Operations
  1156.  
  1157.  
  1158. The   set  of  operations  of  a  type  includes  the  explicitly  declared
  1159. subprograms that have a parameter or result of the type;  such  subprograms
  1160. are necessarily declared after the type declaration.
  1161.  
  1162. The  remaining  operations  are  each  implicitly declared for a given type
  1163. declaration, immediately  after  the  type  definition.   These  implicitly
  1164. declared operations comprise the basic operations, the predefined operators
  1165. (see  4.5),  and  enumeration  literals.   In  the  case  of a derived type
  1166. declaration,  the  implicitly  declared  operations  include  any   derived
  1167. subprograms.    The   operations  implicitly  declared  for  a  given  type
  1168. declaration occur after the type declaration and before the  next  explicit
  1169. declaration,  if  any.   The  implicit  declarations of derived subprograms
  1170. occur last.
  1171.  
  1172. A basic operation is an operation that is inherent in one of the following:
  1173.  
  1174.   -  An assignment  (in  assignment  statements  and  initializations),  an
  1175.      allocator, a membership test, or a short-circuit control form.
  1176.  
  1177.   -  A selected component, an indexed component, or a slice.
  1178.  
  1179.   -  A  qualification  (in  qualified  expressions),   an   explicit   type
  1180.      conversion,  or  an  implicit  type  conversion  of  a  value  of type
  1181.      universal_integer or universal_real  to  the  corresponding  value  of
  1182.      another numeric type.
  1183.  
  1184.  
  1185.                                   3 - 17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.   -  A numeric literal (for a universal type), the  literal  null  (for  an
  1195.      access type), a string literal, an aggregate, or an attribute.
  1196.  
  1197. For every type or subtype T, the following attribute is defined:
  1198.  
  1199. T'BASE     The base type of T.  This  attribute  is  allowed  only  as  the
  1200.            prefix   of   the  name  of  another  attribute:   for  example,
  1201.            T'BASE'FIRST.
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                   3 - 18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260. Note:
  1261.  
  1262. Each literal is an operation  whose  evaluation  yields  the  corresponding
  1263. value  (see  4.2).  Likewise, an aggregate is an operation whose evaluation
  1264. yields a value of a composite type (see 4.3).  Some operations  of  a  type
  1265. operate  on  values  of  the  type,  for  example, predefined operators and
  1266. certain subprograms and attributes.  The evaluation of some operations of a
  1267. type returns a value  of  the  type,  for  example,  literals  and  certain
  1268. functions,   attributes,   and  predefined  operators.   Assignment  is  an
  1269. operation that operates on an object and a value.  The  evaluation  of  the
  1270. operation corresponding to a selected component, an indexed component, or a
  1271. slice, yields the object or value denoted by this form of name.
  1272.  
  1273.  
  1274. References:  aggregate 4.3, allocator 4.8, assignment 5.2, attribute 4.1.4,
  1275. character   literal  2.5,  composite  type  3.3,  conversion  4.6,  derived
  1276. subprogram 3.4, enumeration literal 3.5.1, formal parameter  6.1,  function
  1277. 6.5,  indexed component 4.1.1, initial value 3.2.1, literal 4.2, membership
  1278. test 4.5 4.5.2, null literal 3.8, numeric literal 2.4,  numeric  type  3.5,
  1279. object  3.2.1,  6.1,  predefined  operator  4.5,  qualified expression 4.7,
  1280. selected component 4.1.3,  short-circuit  control  form  4.5  4.5.1,  slice
  1281. 4.1.2,  string  literal  2.6,  subprogram  6,  subtype  3.3, type 3.3, type
  1282. declaration 3.3.1, universal_integer type 3.5.4, universal_real type 3.5.6,
  1283. universal type 4.10
  1284.  
  1285.  
  1286.  
  1287. 3.4  Derived Types
  1288.  
  1289.  
  1290. A derived type definition defines a new (base) type  whose  characteristics
  1291. are  derived from those of a parent type;  the new type is called a derived
  1292. type.  A derived type definition further defines a derived  subtype,  which
  1293. is a subtype of the derived type.
  1294.  
  1295.     derived_type_definition ::= new subtype_indication
  1296.  
  1297. The  subtype indication that occurs after the reserved word new defines the
  1298. parent subtype.  The parent type is the base type of  the  parent  subtype.
  1299. If  a constraint exists for the parent subtype, a similar constraint exists
  1300. for the  derived  subtype;   the  only  difference  is  that  for  a  range
  1301. constraint,  and  likewise  for  a  floating or fixed point constraint that
  1302. includes a range constraint, the value of each bound  is  replaced  by  the
  1303. corresponding  value  of  the  derived  type.   The  characteristics of the
  1304. derived type are defined as follows:
  1305.  
  1306.   -  The derived type belongs to the same class  of  types  as  the  parent
  1307.      type.   The  set  of possible values for the derived type is a copy of
  1308.      the set of possible values for the parent type.  If the parent type is
  1309.      composite, then the same components exist for the  derived  type,  and
  1310.      the subtype of corresponding components is the same.
  1311.  
  1312.   -  For each basic operation of the parent type, there is a  corresponding
  1313.      basic  operation  of  the derived type.  Explicit type conversion of a
  1314.      value of the parent type into the corresponding value of  the  derived
  1315.  
  1316.  
  1317.                                   3 - 19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.      type is allowed and vice versa as explained in section 4.6.
  1327.  
  1328.   -  For each enumeration literal or predefined operator of the parent type
  1329.      there is a corresponding operation for the derived type.
  1330.  
  1331.   -  If the parent type is a task type, then for each entry of  the  parent
  1332.      type there is a corresponding entry for the derived type.
  1333.  
  1334.   -  If a default expression exists for a component of an object having the
  1335.      parent  type,  then  the  same  default  expression  is  used  for the
  1336.      corresponding component of an object having the derived type.
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                   3 - 20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.   -  If the parent type is an access type, then the parent and the  derived
  1393.      type  share the same collection;  there is a null access value for the
  1394.      derived type and it is the default initial value of that type.
  1395.  
  1396.   -  If an explicit representation clause exists for the parent type and if
  1397.      this clause appears before the derived type definition, then there  is
  1398.      a  corresponding  representation  clause  (an  implicit  one)  for the
  1399.      derived type.
  1400.  
  1401.   -  Certain subprograms that are operations of the parent type are said to
  1402.      be derivable.  For each derivable subprogram of the parent type, there
  1403.      is a corresponding derived subprogram for the derived type.  Two kinds
  1404.      of derivable subprograms exist.  First, if the parent type is declared
  1405.      immediately within the visible part of a package,  then  a  subprogram
  1406.      that is itself explicitly declared immediately within the visible part
  1407.      becomes  derivable  after  the  end  of  the visible part, if it is an
  1408.      operation of the parent type.   (The  explicit  declaration  is  by  a
  1409.      subprogram   declaration,   a   renaming  declaration,  or  a  generic
  1410.      instantiation.)  Second, if the parent type is itself a derived  type,
  1411.      then  any  subprogram  that  has  been  derived by this parent type is
  1412.      further derivable, unless the parent type is declared in  the  visible
  1413.      part  of a package and the derived subprogram is hidden by a derivable
  1414.      subprogram of the first kind.
  1415.  
  1416. Each operation of the derived type is implicitly declared at the  place  of
  1417. the  derived  type  declaration.   The implicit declarations of any derived
  1418. subprograms occur last.
  1419.  
  1420. The specification  of  a  derived  subprogram  is  obtained  implicitly  by
  1421. systematic  replacement  of  the  parent  type  by  the derived type in the
  1422. specification of the derivable subprogram.  Any subtype of the parent  type
  1423. is  likewise  replaced  by  a  subtype  of  the derived type with a similar
  1424. constraint (as for the transformation of a constraint of the parent subtype
  1425. into the corresponding constraint of the derived  subtype).   Finally,  any
  1426. expression  of  the  parent  type  is  made  to  be  the  operand of a type
  1427. conversion that yields a result of the derived type.
  1428.  
  1429. Calling a derived subprogram is equivalent  to  calling  the  corresponding
  1430. subprogram  of  the  parent type, in which each actual parameter that is of
  1431. the derived type is replaced by a type conversion of this actual  parameter
  1432. to the parent type (this means that a conversion to the parent type happens
  1433. before  the  call for the modes in and in out;  a reverse conversion to the
  1434. derived type happens after the call for the  modes  in  out  and  out,  see
  1435. 6.4.1).   In  addition, if the result of a called function is of the parent
  1436. type, this result is converted to the derived type.
  1437.  
  1438. If a derived or private type is declared  immediately  within  the  visible
  1439. part  of  a  package, then, within this visible part, this type must not be
  1440. used as the parent type of a derived type definition.  (For private  types,
  1441. see also section 7.4.1.)
  1442.  
  1443. For the elaboration of a derived type definition, the subtype indication is
  1444. first  elaborated,  the  derived  type  is  then  created, and finally, the
  1445. derived subtype is created.
  1446.  
  1447.  
  1448.  
  1449.                                   3 - 21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458. Examples:
  1459.  
  1460.     type LOCAL_COORDINATE is new COORDINATE;   --  two different types
  1461.     type MIDWEEK is new DAY range TUE .. THU;  --  see 3.5.1
  1462.     type COUNTER is new POSITIVE;              --  same range as POSITIVE
  1463.  
  1464.     type SPECIAL_KEY is new KEY_MANAGER.KEY;   --  see 7.4.2
  1465.     -- the derived subprograms have the following specifications:
  1466.  
  1467.     -- procedure GET_KEY(K : out SPECIAL_KEY);
  1468.     -- function "<"(X,Y : SPECIAL_KEY) return BOOLEAN;
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                   3 - 22
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524. Notes:
  1525.  
  1526. The rules of derivation of basic operations and enumeration literals  imply
  1527. that  the  notation for any literal or aggregate of the derived type is the
  1528. same as for the parent type;  such literals and aggregates are said  to  be
  1529. overloaded.   Similarly,  it  follows  that  the  notation  for  denoting a
  1530. component, a discriminant, an entry, a slice, or an attribute is  the  same
  1531. for the derived type as for the parent type.
  1532.  
  1533. Hiding  of a derived subprogram is allowed even within the same declarative
  1534. region (see 8.3).  A derived subprogram hides a  predefined  operator  that
  1535. has the same parameter and result type profile (see 6.6).
  1536.  
  1537. A  generic  subprogram  declaration  is  not  derivable since it declares a
  1538. generic unit rather than a subprogram.  On the other hand, an instantiation
  1539. of a generic subprogram is a (nongeneric) subprogram, which is derivable if
  1540. it satisfies the requirements for derivability of subprograms.
  1541.  
  1542. If the parent type is a boolean type, the predefined  relational  operators
  1543. of  the  derived  type deliver a result of the predefined type BOOLEAN (see
  1544. 4.5.2).
  1545.  
  1546. If a representation clause is given for the parent type but  appears  after
  1547. the  derived  type declaration, then no corresponding representation clause
  1548. applies to the derived type;  hence an explicit representation  clause  for
  1549. such a derived type is allowed.
  1550.  
  1551. For  a  derived subprogram, if a parameter belongs to the derived type, the
  1552. subtype of this parameter need not  have  any  value  in  common  with  the
  1553. derived subtype.
  1554.  
  1555. References:   access  value  3.8,  actual  parameter  6.4.1, aggregate 4.3,
  1556. attribute 4.1.4, base type 3.3, basic operation 3.3.3, boolean type  3.5.3,
  1557. bound  of  a  range  3.5, class of type 3.3, collection 3.8, component 3.3,
  1558. composite type  3.3,  constraint  3.3,  conversion  4.6,  declaration  3.1,
  1559. declarative region 8.1, default expression 3.2.1, default initial value for
  1560. an   access  type  3.8,  discriminant  3.3,  elaboration  3.9,  entry  9.5,
  1561. enumeration literal 3.5.1, floating point  constraint  3.5.7,  fixed  point
  1562. constraint   3.5.9,  formal  parameter  6.1,  function  call  6.4,  generic
  1563. declaration 12.1, immediately within 8.1, implicit declaration 3.1, literal
  1564. 4.2, mode 6.1, overloading 6.6 8.7, package 7, package  specification  7.1,
  1565. parameter  association  6.4,  predefined  operator  4.5,  private type 7.4,
  1566. procedure  6,  procedure  call  statement  6.4,   range   constraint   3.5,
  1567. representation  clause  13.1, reserved word 2.9, slice 4.1.2, subprogram 6,
  1568. subprogram specification 6.1, subtype indication 3.3.2, subtype  3.3,  type
  1569. 3.3, type definition 3.3.1, visible part 7.2
  1570.  
  1571.  
  1572.  
  1573. 3.5  Scalar Types
  1574.  
  1575.  
  1576. Scalar  types  comprise  enumeration  types, integer types, and real types.
  1577. Enumeration types and integer types are called discrete types;  each  value
  1578. of  a  discrete  type  has  a  position  number  which is an integer value.
  1579.  
  1580.  
  1581.                                   3 - 23
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590. Integer types and real types are called numeric types.   All  scalar  types
  1591. are  ordered,  that  is,  all relational operators are predefined for their
  1592. values.
  1593.  
  1594.     range_constraint ::=  range range
  1595.  
  1596.     range ::=  range_attribute
  1597.        | simple_expression .. simple_expression
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                   3 - 24
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656. A range specifies a subset of values of a scalar type.  The range  L  ..  R
  1657. specifies  the values from L to R inclusive if the relation L <= R is true.
  1658. The values L and R are called the lower bound and upper bound of the range,
  1659. respectively.  A value V is said  to  satisfy  a  range  constraint  if  it
  1660. belongs  to  the  range;  the value V is said to belong to the range if the
  1661. relations L <= V and V <= R are both TRUE.  A null range  is  a  range  for
  1662. which  the  relation R < L is TRUE;  no value belongs to a null range.  The
  1663. operators <= and < in the above definitions are the predefined operators of
  1664. the scalar type.
  1665.  
  1666. If a range constraint is used in a subtype indication, either  directly  or
  1667. as  part  of  a  floating or fixed point constraint, the type of the simple
  1668. expressions (likewise,  of the bounds of a range  attribute)  must  be  the
  1669. same  as the base type of the type mark of the subtype indication.  A range
  1670. constraint is compatible with a subtype if each bound of the range  belongs
  1671. to the subtype, or if the range constraint defines a null range;  otherwise
  1672. the range constraint is not compatible with the subtype.
  1673.  
  1674. The  elaboration  of  a  range constraint consists of the evaluation of the
  1675. range.  The evaluation of a range defines its lower  bound  and  its  upper
  1676. bound.   If  simple  expressions  are  given  to  specify  the  bounds, the
  1677. evaluation of the range evaluates these simple expressions  in  some  order
  1678. that is not defined by the language.
  1679.  
  1680. Attributes
  1681.  
  1682. For  any scalar type T or for any subtype T of a scalar type, the following
  1683. attributes are defined:
  1684.  
  1685. T'FIRST     Yields the lower bound of T.  The value of this  attribute  has
  1686.             the same type as T.
  1687.  
  1688. T'LAST      Yields the upper bound of T.  The value of this  attribute  has
  1689.             the same type as T.
  1690.  
  1691. Note:
  1692.  
  1693. Indexing and iteration rules use values of discrete types.
  1694.  
  1695. References:   attribute  4.1.4,  constraint  3.3,  enumeration  type 3.5.1,
  1696. erroneous 1.6, evaluation 4.5, fixed point constraint 3.5.9, floating point
  1697. constraint 3.5.7, index 3.6, integer type 3.5.4, loop statement 5.5,  range
  1698. attribute  3.6.2, real type 3.5.6, relational operator 4.5 4.5.2, satisfy a
  1699. constraint 3.3, simple expression 4.4, subtype indication 3.3.2, type  mark
  1700. 3.3.2
  1701.  
  1702.  
  1703.  
  1704. 3.5.1  Enumeration Types
  1705.  
  1706.  
  1707. An enumeration type definition defines an enumeration type.
  1708.  
  1709.     enumeration_type_definition ::=
  1710.        (enumeration_literal_specification {, enumeration_literal_specification})
  1711.  
  1712.  
  1713.                                   3 - 25
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.     enumeration_literal_specification ::=  enumeration_literal
  1723.  
  1724.     enumeration_literal ::=  identifier | character_literal
  1725.  
  1726. The  identifiers  and  character  literals  listed  by  an enumeration type
  1727. definition must be distinct.  Each enumeration literal specification is the
  1728. declaration of the corresponding enumeration literal:  this declaration  is
  1729. equivalent  to  the declaration of a parameterless function, the designator
  1730. being the enumeration literal, and the result type  being  the  enumeration
  1731. type.   The  elaboration  of  an  enumeration  type  definition  creates an
  1732. enumeration type;  this elaboration  includes  that  of  every  enumeration
  1733. literal specification.
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.                                   3 - 26
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788. Each  enumeration  literal  yields  a  different  enumeration  value.   The
  1789. predefined order relations between enumeration values follow the  order  of
  1790. corresponding  position  numbers.   The position number of the value of the
  1791. first listed enumeration literal is zero;  the  position  number  for  each
  1792. other enumeration literal is one more than for its predecessor in the list.
  1793.  
  1794. If  the  same identifier or character literal is specified in more than one
  1795. enumeration type definition, the corresponding  literals  are  said  to  be
  1796. overloaded.  At any place where an overloaded enumeration literal occurs in
  1797. the  text  of  a  program,  the  type  of  the  enumeration literal must be
  1798. determinable from the context (see 8.7).
  1799.  
  1800. Examples:
  1801.  
  1802.     type DAY    is (MON, TUE, WED, THU, FRI, SAT, SUN);
  1803.     type SUIT   is (CLUBS, DIAMONDS, HEARTS, SPADES);
  1804.     type GENDER is (M, F);
  1805.     type LEVEL  is (LOW, MEDIUM, URGENT);
  1806.     type COLOR  is (WHITE, RED, YELLOW, GREEN, BLUE, BROWN, BLACK);
  1807.     type LIGHT  is (RED, AMBER, GREEN); -- RED and GREEN are overloaded
  1808.  
  1809.     type HEXA   is ('A', 'B', 'C', 'D', 'E', 'F');
  1810.     type MIXED  is ('A', 'B', '*', B, NONE, '?', '%');
  1811.  
  1812.     subtype WEEKDAY is DAY   range MON .. FRI;
  1813.     subtype MAJOR   is SUIT  range HEARTS .. SPADES;
  1814.     subtype RAINBOW is COLOR range RED .. BLUE;  --  the color RED, not the light
  1815.  
  1816. Note:
  1817.  
  1818. If an enumeration literal occurs in  a  context  that  does  not  otherwise
  1819. suffice  to  determine  the  type of the literal, then qualification by the
  1820. name of the enumeration type is one way to resolve the ambiguity (see 8.7).
  1821.  
  1822.  
  1823. References:   character  literal  2.5,  declaration  3.1,  designator  6.1,
  1824. elaboration  3.9,  6.1, function 6.5, identifier 2.3, name 4.1, overloading
  1825. 6.6 8.7, position number 3.5, qualified expression 4.7, relational operator
  1826. 4.5 4.5.2, type 3.3, type definition 3.3.1
  1827.  
  1828.  
  1829.  
  1830. 3.5.2  Character Types
  1831.  
  1832.  
  1833. An enumeration type is said to be a character type if at least one  of  its
  1834. enumeration literals is a character literal.  The predefined type CHARACTER
  1835. is  a  character  type  whose  values  are  the 128 characters of the ASCII
  1836. character set.  Each of the 95 graphic characters of this character set  is
  1837. denoted by the corresponding character literal.
  1838.  
  1839. Example:
  1840.  
  1841.     type ROMAN_DIGIT is ('I', 'V', 'X', 'L', 'C', 'D', 'M');
  1842.  
  1843.  
  1844.  
  1845.                                   3 - 27
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854. Notes:
  1855.  
  1856. The predefined package ASCII includes the declaration of constants denoting
  1857. control  characters  and  of constants denoting graphic characters that are
  1858. not in the basic character set.
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.                                   3 - 28
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920. A conventional character set such as EBCDIC can be declared as a  character
  1921. type;   the  internal  codes  of  the  characters  can  be  specified by an
  1922. enumeration representation clause as explained in section 13.3.
  1923.  
  1924. References:  ascii predefined package C,  basic  character  2.1,  character
  1925. literal  2.5,  constant  3.2.1,  declaration  3.1,  enumeration type 3.5.1,
  1926. graphic character 2.1, identifier 2.3, literal 4.2, predefined type C, type
  1927. 3.3
  1928.  
  1929.  
  1930.  
  1931. 3.5.3  Boolean Types
  1932.  
  1933.  
  1934. There is a predefined enumeration type named BOOLEAN.  It contains the  two
  1935. literals  FALSE and TRUE ordered with the relation FALSE < TRUE.  A boolean
  1936. type is either the type BOOLEAN or a type  that  is  derived,  directly  or
  1937. indirectly, from a boolean type.
  1938.  
  1939. References:   derived type 3.4, enumeration literal 3.5.1, enumeration type
  1940. 3.5.1, relational operator 4.5 4.5.2, type 3.3
  1941.  
  1942.  
  1943.  
  1944. 3.5.4  Integer Types
  1945.  
  1946.  
  1947. An integer type definition defines an integer  type  whose  set  of  values
  1948. includes at least those of the specified range.
  1949.  
  1950.     integer_type_definition ::=  range_constraint
  1951.  
  1952. If  a range constraint is used as an integer type definition, each bound of
  1953. the range must be defined by a static expression of some integer type,  but
  1954. the  two  bounds need not have the same integer type.  (Negative bounds are
  1955. allowed.)
  1956.  
  1957. A type declaration of the form:
  1958.  
  1959.     type T is range L .. R;
  1960.  
  1961. is, by definition, equivalent to the following declarations:
  1962.  
  1963.     type integer_type is new predefined_integer_type;
  1964.     subtype T is integer_type range integer_type(L) .. integer_type(R);
  1965.  
  1966. where integer_type is an anonymous type, and where the  predefined  integer
  1967. type  is  implicitly  selected  by the implementation, so as to contain the
  1968. values L to R inclusive.  The integer type declaration is illegal  if  none
  1969. of  the  predefined  integer  types  satisfies  this requirement, excepting
  1970. universal_integer.  The elaboration of the declaration of an  integer  type
  1971. consists   of   the   elaboration   of  the  equivalent  type  and  subtype
  1972. declarations.
  1973.  
  1974.  
  1975.  
  1976.  
  1977.                                   3 - 29
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986. The predefined integer types include the type INTEGER.   An  implementation
  1987. may  also  have  predefined  types  such as SHORT_INTEGER and LONG_INTEGER,
  1988. which have (substantially) shorter and longer  ranges,  respectively,  than
  1989. INTEGER.   The  range  of each of these types must be symmetric about zero,
  1990. excepting an extra negative value which may exist in some  implementations.
  1991. The base type of each of these types is the type itself.
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.                                   3 - 30
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052. Integer  literals  are the literals of an anonymous predefined integer type
  2053. that is called universal_integer in this reference manual.   Other  integer
  2054. types  have  no  literals.   However, for each integer type there exists an
  2055. implicit conversion  that  converts  a  universal_integer  value  into  the
  2056. corresponding  value (if any) of the integer type.  The circumstances under
  2057. which these implicit conversions are invoked are described in section  4.6.
  2058.  
  2059. The  position  number of an integer value is the corresponding value of the
  2060. type universal_integer.
  2061.  
  2062. The same arithmetic operators are predefined for  all  integer  types  (see
  2063. 4.5).   The  exception  NUMERIC_ERROR  is  raised  by  the  execution of an
  2064. operation (in particular an implicit conversion) that  cannot  deliver  the
  2065. correct  result  (that  is,  if the value corresponding to the mathematical
  2066. result is not a  value of the integer type).  However, an implementation is
  2067. not required to raise the exception NUMERIC_ERROR if the operation is  part
  2068. of a larger expression whose result can be computed correctly, as described
  2069. in section 11.6.
  2070.  
  2071. Examples:
  2072.  
  2073.     type PAGE_NUM  is range 1 .. 2_000;
  2074.     type LINE_SIZE is range 1 .. MAX_LINE_SIZE;
  2075.  
  2076.     subtype SMALL_INT   is INTEGER   range -10 .. 10;
  2077.     subtype COLUMN_PTR  is LINE_SIZE range 1 .. 10;
  2078.     subtype BUFFER_SIZE is INTEGER   range 0 .. MAX;
  2079.  
  2080. Notes:
  2081.  
  2082. The name declared by an integer type declaration is a subtype name.  On the
  2083. other  hand,  the  predefined  operators of an integer type deliver results
  2084. whose range is defined by the parent predefined type;  such a  result  need
  2085. not  belong to the declared subtype, in which case an attempt to assign the
  2086. result  to  a  variable  of  the  integer  subtype  raises  the   exception
  2087. CONSTRAINT_ERROR.
  2088.  
  2089. The  smallest  (most  negative)  value  supported by the predefined integer
  2090. types of an implementation is  the  named  number  SYSTEM.MIN_INT  and  the
  2091. largest (most positive) value is SYSTEM.MAX_INT (see 13.7).
  2092.  
  2093. References:   anonymous  type  3.3.1,  belong  to a subtype 3.3, bound of a
  2094. range 3.5, constraint_error exception 11.1, conversion 4.6, identifier 2.3,
  2095. integer literal 2.4, literal 4.2, numeric_error exception 11.1, parent type
  2096. 3.4, predefined operator 4.5, range constraint 3.5, static expression  4.9,
  2097. subtype  declaration  3.3.2, system predefined package 13.7, type 3.3, type
  2098. declaration 3.3.1, type definition 3.3.1, universal type 4.10
  2099.  
  2100.  
  2101.  
  2102. 3.5.5  Operations of Discrete Types
  2103.  
  2104.  
  2105. The basic operations of a discrete type include the operations involved  in
  2106. assignment,  the  membership  tests, and qualification;  for a boolean type
  2107.  
  2108.  
  2109.                                   3 - 31
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118. they include the short-circuit control forms;  for  an  integer  type  they
  2119. include  the  explicit  conversion  of values of other numeric types to the
  2120. integer  type,  and  the  implicit  conversion  of  values  of   the   type
  2121. universal_integer to the type.
  2122.  
  2123. Finally, for every discrete type or subtype T, the basic operations include
  2124. the  attributes  listed  below.   In this presentation, T is referred to as
  2125. being  a  subtype  (the  subtype  T)  for  any  property  that  depends  on
  2126. constraints imposed by T;  other properties are stated in terms of the base
  2127. type of T.
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.                                   3 - 32
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184. The first group of attributes yield characteristics of the subtype T.  This
  2185. group  includes  the  attribute  BASE (see 3.3.2), the attributes FIRST and
  2186. LAST (see 3.5), the representation attribute SIZE (see  13.7.2),  and   the
  2187. attribute WIDTH defined as follows:
  2188.  
  2189. T'WIDTH     Yields the maximum image length over all values of the  subtype
  2190.             T  (the  image  is  the  sequence of characters returned by the
  2191.             attribute IMAGE, see below).  Yields zero  for  a  null  range.
  2192.             The  value  of this attribute is of the type universal_integer.
  2193.  
  2194. All attributes of the second group are functions with a  single  parameter.
  2195. The corresponding actual parameter is indicated below by X.
  2196.  
  2197. T'POS       This attribute is a function.  The parameter X must be a  value
  2198.             of   the  base  type  of  T.   The  result  type  is  the  type
  2199.             universal_integer.  The result is the position  number  of  the
  2200.             value of the parameter.
  2201.  
  2202. T'VAL       This attribute is a special function with  a  single  parameter
  2203.             which  can be of any integer type.  The result type is the base
  2204.             type of T.  The result is the value whose  position  number  is
  2205.             the  universal_integer value corresponding to X.  The exception
  2206.             CONSTRAINT_ERROR  is  raised  if  the  universal_integer  value
  2207.             corresponding  to  X is not in the range T'POS(T'BASE'FIRST) ..
  2208.             T'POS(T'BASE'LAST).
  2209.  
  2210. T'SUCC      This attribute is a function.  The parameter X must be a  value
  2211.             of  the base type of T.  The result type is the base type of T.
  2212.             The result is the value whose position number  is  one  greater
  2213.             than  that of X.  The exception CONSTRAINT_ERROR is raised if X
  2214.             equals T'BASE'LAST.
  2215.  
  2216. T'PRED      This attribute is a function.  The parameter X must be a  value
  2217.             of  the base type of T.  The result type is the base type of T.
  2218.             The result is the value whose position number is one less  than
  2219.             that  of  X.   The  exception  CONSTRAINT_ERROR  is raised if X
  2220.             equals T'BASE'FIRST.
  2221.  
  2222. T'IMAGE     This attribute is a function.  The parameter X must be a  value
  2223.             of  the base type of T.  The result type is the predefined type
  2224.             STRING.  The result is the image of the value of X, that is,  a
  2225.             sequence  of characters representing the value in display form.
  2226.             The image of an integer  value  is  the  corresponding  decimal
  2227.             literal;   without  underlines,  leading  zeros,  exponent,  or
  2228.             trailing spaces;  but with a single leading character  that  is
  2229.             either  a  minus sign or a space.  The lower bound of the image
  2230.             is one.
  2231.  
  2232.             The image of an enumeration value is either  the  corresponding
  2233.             identifier in upper case or the corresponding character literal
  2234.             (including  the two apostrophes);  neither leading nor trailing
  2235.             spaces are included.  The image of a character C, other than  a
  2236.             graphic   character,   is   implementation-defined;   the  only
  2237.             requirement is that the  image  must  be  such  that  C  equals
  2238.             CHARACTER'VALUE(CHARACTER'IMAGE(C)).
  2239.  
  2240.  
  2241.                                   3 - 33
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250. T'VALUE     This attribute is a function.  The parameter X must be a  value
  2251.             of  the  predefined  type  STRING.  The result type is the base
  2252.             type of T.  Any leading and any trailing spaces of the sequence
  2253.             of characters that corresponds to the parameter are ignored.
  2254.  
  2255.             For an enumeration type, if the sequence of characters has  the
  2256.             syntax of an enumeration literal and if this literal exists for
  2257.             the base type of T, the result is the corresponding enumeration
  2258.             value.   For an integer type, if the sequence of characters has
  2259.             the syntax of an  integer  literal,  with  an  optional  single
  2260.             leading character that is a plus or minus sign, and if there is
  2261.             a corresponding value in the base type of T, the result is this
  2262.             value.   In  any  other case, the exception CONSTRAINT_ERROR is
  2263.             raised.
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.                                   3 - 34
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316. In addition, the attributes A'SIZE and A'ADDRESS are defined for an  object
  2317. A of a discrete type (see 13.7.2).
  2318.  
  2319. Besides the basic operations, the operations of a discrete type include the
  2320. predefined relational operators.  For enumeration types, operations include
  2321. enumeration literals.  For boolean types, operations include the predefined
  2322. unary  logical negation operator not, and the predefined logical operators.
  2323. For integer types, operations include the predefined arithmetic  operators:
  2324. these  are  the  binary and unary adding operators - and +, all multiplying
  2325. operators, the unary operator abs, and the exponentiating operator.
  2326.  
  2327. The operations of a subtype are the corresponding operations  of  its  base
  2328. type   except   for   the   following:    assignment,   membership   tests,
  2329. qualification, explicit type conversions, and the attributes of  the  first
  2330. group;   the  effect  of  each  of  these operations depends on the subtype
  2331. (assignments, membership tests, qualifications, and conversions  involve  a
  2332. subtype check;  attributes of the first group yield a characteristic of the
  2333. subtype).
  2334.  
  2335. Notes:
  2336.  
  2337. For  a  subtype of a discrete type, the results delivered by the attributes
  2338. SUCC, PRED, VAL, and VALUE need not belong to the subtype;  similarly,  the
  2339. actual  parameters  of  the  attributes POS, SUCC, PRED, and IMAGE need not
  2340. belong to the subtype.  The  following  relations  are  satisfied  (in  the
  2341. absence of an exception) by these attributes:
  2342.  
  2343.     T'POS(T'SUCC(X)) = T'POS(X) + 1
  2344.     T'POS(T'PRED(X)) = T'POS(X) - 1
  2345.  
  2346.     T'VAL(T'POS(X))  = X
  2347.     T'POS(T'VAL(N))  = N
  2348.  
  2349. Examples:
  2350.  
  2351.     --  For the types and subtypes declared in section 3.5.1 we have:
  2352.  
  2353.     --  COLOR'FIRST   = WHITE,   COLOR'LAST   = BLACK
  2354.     --  RAINBOW'FIRST = RED,     RAINBOW'LAST = BLUE
  2355.  
  2356.     --  COLOR'SUCC(BLUE) = RAINBOW'SUCC(BLUE) = BROWN
  2357.     --  COLOR'POS(BLUE)  = RAINBOW'POS(BLUE)  = 4
  2358.     --  COLOR'VAL(0)     = RAINBOW'VAL(0)     = WHITE
  2359.  
  2360.  
  2361. References:   abs operator 4.5 4.5.6, assignment 5.2, attribute 4.1.4, base
  2362. type 3.3, basic operation 3.3.3, binary adding operator 4.5 4.5.3,  boolean
  2363. type  3.5.3,  bound  of a range 3.5, character literal 2.5, constraint 3.3,
  2364. constraint_error  exception  11.1,  conversion  4.6,  discrete  type   3.5,
  2365. enumeration literal 3.5.1, exponentiating operator 4.5 4.5.6, function 6.5,
  2366. graphic character 2.1, identifier 2.3, integer type 3.5.4, logical operator
  2367. 4.5  4.5.1,  membership test 4.5 4.5.2, multiplying operator 4.5 4.5.5, not
  2368. operator 4.5 4.5.6, numeric literal 2.4,  numeric  type  3.5,  object  3.2,
  2369. operation  3.3,  position  number  3.5, predefined operator 4.5, predefined
  2370. type  C,  qualified  expression  4.7,  relational   operator   4.5   4.5.2,
  2371.  
  2372.  
  2373.                                   3 - 35
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382. short-circuit  control form 4.5 4.5.1, string type 3.6.3, subtype 3.3, type
  2383. 3.3,  unary  adding  operator  4.5  4.5.4,  universal_integer  type  3.5.4,
  2384. universal type 4.10
  2385.  
  2386.  
  2387.  
  2388.  
  2389.  
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.                                   3 - 36
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448. 3.5.6  Real Types
  2449.  
  2450.  
  2451. Real types provide approximations to the real numbers, with relative bounds
  2452. on  errors  for  floating  point  types, and with absolute bounds for fixed
  2453. point types.
  2454.  
  2455.     real_type_definition ::=
  2456.        floating_point_constraint | fixed_point_constraint
  2457.  
  2458. A set of numbers called model numbers is associated with  each  real  type.
  2459. Error  bounds  on the predefined operations are given in terms of the model
  2460. numbers.  An implementation of the type must include at least  these  model
  2461. numbers and represent them exactly.
  2462.  
  2463. An  implementation-dependent  set  of  numbers, called the safe numbers, is
  2464. also associated with each real type.  The set of safe  numbers  of  a  real
  2465. type must include at least the set of model numbers of the type.  The range
  2466. of  safe  numbers  is allowed to be larger than the range of model numbers,
  2467. but error bounds on the predefined operations for safe numbers are given by
  2468. the same rules as  for  model  numbers.   Safe  numbers  therefore  provide
  2469. guaranteed error bounds for operations on an implementation-dependent range
  2470. of  numbers;   in  contrast, the range of model numbers depends only on the
  2471. real type definition and is therefore independent of the implementation.
  2472.  
  2473. Real literals are the literals of an anonymous predefined real type that is
  2474. called universal_real in this reference manual.  Other real types  have  no
  2475. literals.  However, for each real type, there exists an implicit conversion
  2476. that  converts  a  universal_real value into a value of the real type.  The
  2477. conditions under which these implicit conversions are invoked are described
  2478. in section 4.6.   If  the  universal_real  value  is  a  safe  number,  the
  2479. implicit conversion delivers the corresponding value;  if it belongs to the
  2480. range  of  safe  numbers but is not a safe number, then the converted value
  2481. can be any value within the range defined by the safe  numbers  next  above
  2482. and below the universal_real value.
  2483.  
  2484. The  execution of an operation that yields a value of a real type may raise
  2485. the exception NUMERIC_ERROR, as explained in section 4.5.7,  if  it  cannot
  2486. deliver a correct result (that is, if the value corresponding to one of the
  2487. possible  mathematical  results  does  not  belong  to  the  range  of safe
  2488. numbers);  in particular, this exception  can  be  raised  by  an  implicit
  2489. conversion.   However,  an  implementation  is  not  required  to raise the
  2490. exception NUMERIC_ERROR if the operation is part  of  a  larger  expression
  2491. whose result can be computed correctly (see 11.6).
  2492.  
  2493. The  elaboration  of a real type definition includes the elaboration of the
  2494. floating or fixed point constraint and creates a real type.
  2495.  
  2496. Note:
  2497.  
  2498. An algorithm written to rely only upon  the  minimum  numerical  properties
  2499. guaranteed  by  the  type  definition  for  model  numbers will be portable
  2500. without further precautions.
  2501.  
  2502.  
  2503.  
  2504.  
  2505.                                   3 - 37
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514. References:  conversion 4.6, elaboration 3.9, fixed point constraint 3.5.9,
  2515. floating point constraint 3.5.7, literal 4.2, numeric_error exception 11.1,
  2516. predefined operation 3.3.3, real literal 2.4,  type  3.3,  type  definition
  2517. 3.3.1, universal type 4.10
  2518.  
  2519.  
  2520.  
  2521.  
  2522.  
  2523.  
  2524.  
  2525.  
  2526.  
  2527.  
  2528.  
  2529.  
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                   3 - 38
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580. 3.5.7  Floating Point Types
  2581.  
  2582.  
  2583. For  floating  point  types,  the  error  bound  is specified as a relative
  2584. precision by giving the required  minimum  number  of  significant  decimal
  2585. digits.
  2586.  
  2587.     floating_point_constraint ::=
  2588.        floating_accuracy_definition [range_constraint]
  2589.  
  2590.     floating_accuracy_definition ::=  digits static_simple_expression
  2591.  
  2592. The  minimum number of significant decimal digits is specified by the value
  2593. of the static simple expression of the floating accuracy definition.   This
  2594. value  must belong to some integer type and must be positive (nonzero);  it
  2595. is denoted by D in the remainder of this section.  If  the  floating  point
  2596. constraint  is  used  as  a  real  type  definition  and  includes  a range
  2597. constraint, then each bound of the  range  must  be  defined  by  a  static
  2598. expression  of  some  real  type, but the two bounds need not have the same
  2599. real type.
  2600.  
  2601. For a given radix, the following canonical form is defined for any floating
  2602. point model number other than zero:
  2603.  
  2604.     sign * mantissa * (radix ** exponent)
  2605.  
  2606. In this form: sign is either +1 or -1;  mantissa is expressed in  a  number
  2607. base  given by radix; and exponent is an integer number (possibly negative)
  2608. such that the integer part of mantissa is zero and the first digit  of  its
  2609. fractional part is not a zero.
  2610.  
  2611. The  specified  number  D  is the minimum number of decimal digits required
  2612. after the point in the decimal mantissa (that is, if radix  is  ten).   The
  2613. value  of D in turn determines a corresponding number B that is the minimum
  2614. number of binary digits required after the point  in  the  binary  mantissa
  2615. (that is, if radix is two).  The number B associated with D is the smallest
  2616. value  such  that the relative precision of the binary form is no less than
  2617. that specified for the decimal form.  (The number B  is  the  integer  next
  2618. above (D*log(10)/log(2)) + 1.)
  2619.  
  2620. The  model  numbers defined by a floating accuracy definition comprise zero
  2621. and all numbers whose binary canonical form has exactly B digits after  the
  2622. point  in  the  mantissa  and  an  exponent in the range -4*B .. +4*B.  The
  2623. guaranteed minimum accuracy of operations  of  a  floating  point  type  is
  2624. defined in terms of the model numbers of the floating point constraint that
  2625. forms the corresponding real type definition (see 4.5.7).
  2626.  
  2627. The   predefined   floating   point  types  include  the  type  FLOAT.   An
  2628. implementation may also have  predefined  types  such  as  SHORT_FLOAT  and
  2629. LONG_FLOAT,   which   have   (substantially)   less   and   more  accuracy,
  2630. respectively, than FLOAT.  The base type of each predefined floating  point
  2631. type  is  the  type  itself.  The model numbers of each predefined floating
  2632. point type are defined in terms of the number D of decimal digits  returned
  2633. by the attribute DIGITS (see 3.5.8).
  2634.  
  2635.  
  2636.  
  2637.                                   3 - 39
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646. For  each  predefined  floating point type (consequently also for each type
  2647. derived therefrom), a set of safe numbers is defined as follows.  The  safe
  2648. numbers  have  the same number B of mantissa digits as the model numbers of
  2649. the type  and  have  an  exponent  in  the  range  -E  ..  +E  where  E  is
  2650. implementation-defined  and  at  least  equal  to the 4*B of model numbers.
  2651. (Consequently, the safe numbers include  the  model  numbers.)   The  rules
  2652. defining  the  accuracy of operations with model and safe numbers are given
  2653. in section 4.5.7.  The safe numbers of a subtype  are  those  of  its  base
  2654. type.
  2655.  
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.  
  2674.  
  2675.  
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682.  
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.                                   3 - 40
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712. A floating point type declaration of one of the two forms (that is, with or
  2713. without the optional range constraint indicated by the square brackets):
  2714.  
  2715.     type T is digits D [range L .. R];
  2716.  
  2717. is, by definition, equivalent to the following declarations:
  2718.  
  2719.     type floating_point_type is new predefined_floating_point_type;
  2720.     subtype T is floating_point_type digits D
  2721.        [range floating_point_type(L) .. floating_point_type(R)];
  2722.  
  2723. where  floating_point_type  is  an anonymous type, and where the predefined
  2724. floating point type is implicitly selected by the  implementation  so  that
  2725. its  model numbers include the model numbers defined by D;  furthermore, if
  2726. a range L .. R is supplied, then both L and R must belong to the  range  of
  2727. safe  numbers.   The  floating  point declaration is illegal if none of the
  2728. predefined floating point types  satisfies  these  requirements,  excepting
  2729. universal_real.   The  maximum  number of digits that can be specified in a
  2730. floating accuracy definition is given by the system-dependent named  number
  2731. SYSTEM.MAX_DIGITS (see 13.7.1).
  2732.  
  2733. The  elaboration  of  a  floating  point  type  declaration consists of the
  2734. elaboration of the equivalent type and subtype declarations.
  2735.  
  2736. If a floating point constraint follows a type mark in a subtype indication,
  2737. the type mark must denote a floating point type or subtype.   The  floating
  2738. point  constraint  is  compatible  with  the type mark only if the number D
  2739. specified in the floating accuracy  definition  is  not  greater  than  the
  2740. corresponding  number  D  for the type or subtype denoted by the type mark.
  2741. Furthermore, if the floating point constraint includes a range  constraint,
  2742. the  floating point constraint is compatible with the type mark only if the
  2743. range constraint is, itself, compatible with the type mark.
  2744.  
  2745. The elaboration of such a subtype indication includes  the  elaboration  of
  2746. the range constraint, if there is one;  it creates a floating point subtype
  2747. whose  model  numbers  are  defined  by the corresponding floating accuracy
  2748. definition.  A value of a floating point type belongs to a  floating  point
  2749. subtype if and only if it belongs to the range defined by the subtype.
  2750.  
  2751. The  same  arithmetic operators are predefined for all floating point types
  2752. (see 4.5).
  2753.  
  2754. Notes:
  2755.  
  2756. A range constraint is allowed  in  a  floating  point  subtype  indication,
  2757. either  directly  after  the  type  mark,  or  as  part of a floating point
  2758. constraint.  In either case the bounds of the range must belong to the base
  2759. type of the type mark (see  3.5).   The  imposition  of  a  floating  point
  2760. constraint on a type mark in a subtype indication cannot reduce the allowed
  2761. range  of  values unless it includes a range constraint (the range of model
  2762. numbers that correspond to the specified number of digits  can  be  smaller
  2763. than  the  range  of  numbers of the type mark).  A value that belongs to a
  2764. floating point subtype need not be a model number of the subtype.
  2765.  
  2766.  
  2767.  
  2768.  
  2769.                                   3 - 41
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778. Examples:
  2779.  
  2780.     type COEFFICIENT is digits 10 range -1.0 .. 1.0;
  2781.  
  2782.     type REAL is digits 8;
  2783.     type MASS is digits 7 range 0.0 .. 1.0E35;
  2784.  
  2785.     subtype SHORT_COEFF is COEFFICIENT digits 5;    --   a subtype with less accuracy
  2786.     subtype PROBABILITY is REAL range 0.0 .. 1.0;   --   a subtype with a smaller range
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.                                   3 - 42
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844. Notes on the examples:
  2845.  
  2846. The implemented accuracy for COEFFICIENT  is  that  of  a  predefined  type
  2847. having  at least 10 digits of precision.  Consequently the specification of
  2848. 5 digits of precision for the subtype SHORT_COEFF is allowed.  The  largest
  2849. model number for the type MASS is approximately 1.27E30 and hence less than
  2850. the  specified  upper bound (1.0E35).  Consequently the declaration of this
  2851. type is legal only if this upper bound is in the range of the safe  numbers
  2852. of  a predefined floating point type having at least 7 digits of precision.
  2853.  
  2854. References:  anonymous type 3.3.1, arithmetic  operator  3.5.5  4.5,  based
  2855. literal  2.4.2,  belong  to a subtype 3.3, bound of a range 3.5, compatible
  2856. 3.3.2, derived type 3.4, digit 2.1, elaboration 3.1 3.9, error bound 3.5.6,
  2857. exponent 2.4.1 integer type  3.5.4,  model  number  3.5.6,  operation  3.3,
  2858. predefined operator 4.5, predefined type C, range constraint 3.5, real type
  2859. 3.5.6,  real  type  definition  3.5.6, safe number 3.5.6, simple expression
  2860. 4.4, static expression 4.9, subtype declaration 3.3.2,  subtype  indication
  2861. 3.3.2, subtype 3.3, type 3.3, type declaration 3.3.1, type mark 3.3.2
  2862.  
  2863.  
  2864.  
  2865. 3.5.8  Operations of Floating Point Types
  2866.  
  2867.  
  2868. The  basic  operations  of  a  floating  point  type include the operations
  2869. involved in  assignment,  membership  tests,  qualification,  the  explicit
  2870. conversion of values of other numeric types to the floating point type, and
  2871. the  implicit  conversion of values of the type universal_real to the type.
  2872.  
  2873. In addition, for  every  floating  point  type  or  subtype  T,  the  basic
  2874. operations include the attributes listed below.  In this presentation, T is
  2875. referred  to  as  being  a  subtype  (the  subtype T) for any property that
  2876. depends on constraints imposed by T;  other properties are stated in  terms
  2877. of the base type of T.
  2878.  
  2879. The  first group of attributes yield characteristics of the subtype T.  The
  2880. attributes of this group are the attribute BASE (see 3.3.2), the attributes
  2881. FIRST and LAST (see 3.5), the representation attribute SIZE  (see  13.7.2),
  2882. and the following attributes:
  2883.  
  2884. T'DIGITS     Yields the number of decimal digits in the decimal mantissa of
  2885.              model  numbers  of  the subtype T.  (This attribute yields the
  2886.              number D of section 3.5.7.)  The value of this attribute is of
  2887.              the type universal_integer.
  2888.  
  2889. T'MANTISSA   Yields the number of binary digits in the binary  mantissa  of
  2890.              model  numbers  of  the subtype T.  (This attribute yields the
  2891.              number B of section 3.5.7.)  The value of this attribute is of
  2892.              the type universal_integer.
  2893.  
  2894. T'EPSILON    Yields the absolute value of the difference between the  model
  2895.              number 1.0 and the next model number above, for the subtype T.
  2896.              The value of this attribute is of the type universal_real.
  2897.  
  2898.  
  2899.  
  2900.  
  2901.                                   3 - 43
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910. T'EMAX       Yields the largest exponent value in the binary canonical form
  2911.              of model numbers of the subtype T.  (This attribute yields the
  2912.              product 4*B of section 3.5.7.)  The value of this attribute is
  2913.              of the type  universal_integer.
  2914.  
  2915. T'SMALL      Yields the smallest positive (nonzero)  model  number  of  the
  2916.              subtype  T.   The  value  of  this  attribute  is  of the type
  2917.              universal_real.
  2918.  
  2919. T'LARGE      Yields the largest positive model number  of  the  subtype  T.
  2920.              The value of this attribute is of the type universal_real.
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.                                   3 - 44
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  
  2975.  
  2976. The  attributes  of the second group include the following attributes which
  2977. yield characteristics of the safe numbers:
  2978.  
  2979. T'SAFE_EMAX  Yields the largest exponent value in the binary canonical form
  2980.              of safe numbers of the base type of T.  (This attribute yields
  2981.              the number E of section 3.5.7.)  The value of  this  attribute
  2982.              is of the type universal_integer.
  2983.  
  2984. T'SAFE_SMALL Yields the smallest positive (nonzero) safe number of the base
  2985.              type  of  T.   The  value  of  this  attribute  is of the type
  2986.              universal_real.
  2987.  
  2988. T'SAFE_LARGE Yields the largest positive safe number of the base type of T.
  2989.              The value of this attribute is of the type universal_real.
  2990.  
  2991. In addition, the attributes A'SIZE and A'ADDRESS are defined for an  object
  2992. A  of a floating point type (see 13.7.2).  Finally, for each floating point
  2993. type there are machine-dependent attributes that are not related  to  model
  2994. numbers  and  safe  numbers.   They correspond to the attribute designators
  2995. MACHINE_RADIX,      MACHINE_MANTISSA,      MACHINE_EMAX,      MACHINE_EMIN,
  2996. MACHINE_ROUNDS, and MACHINE_OVERFLOWS (see 13.7.3).
  2997.  
  2998. Besides  the  basic  operations,  the  operations  of a floating point type
  2999. include the relational operators, and the following  predefined  arithmetic
  3000. operators:   the binary and unary adding operators - and +, the multiplying
  3001. operators * and /, the unary operator abs, and the exponentiating operator.
  3002.  
  3003. The operations of a subtype are the corresponding operations  of  the  type
  3004. except  for  the  following:   assignment, membership tests, qualification,
  3005. explicit conversion, and the attributes of the first group;  the effects of
  3006. these operations are redefined in terms of the subtype.
  3007.  
  3008. Notes:
  3009.  
  3010. The  attributes  EMAX,  SMALL,  LARGE,  and  EPSILON   are   provided   for
  3011. convenience.   They  are all related to MANTISSA by the following formulas:
  3012.  
  3013.     T'EMAX    = 4*T'MANTISSA
  3014.     T'EPSILON = 2.0**(1 - T'MANTISSA)
  3015.     T'SMALL   = 2.0**(-T'EMAX - 1)
  3016.     T'LARGE   = 2.0**T'EMAX * (1.0 - 2.0**(-T'MANTISSA))
  3017.  
  3018. The attribute MANTISSA, giving the number of binary digits in the mantissa,
  3019. is itself related to DIGITS.  The  following  relations  hold  between  the
  3020. characteristics of the model numbers and those of the safe numbers:
  3021.  
  3022.     T'BASE'EMAX  <= T'SAFE_EMAX
  3023.     T'BASE'SMALL >= T'SAFE_SMALL
  3024.     T'BASE'LARGE <= T'SAFE_LARGE
  3025.  
  3026. The attributes T'FIRST and T'LAST need not yield model or safe numbers.  If
  3027. a  certain  number  of  digits is specified in the declaration of a type or
  3028. subtype T, the attribute T'DIGITS yields this number.
  3029.  
  3030.  
  3031.  
  3032.  
  3033.                                   3 - 45
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042. References:   abs  operator  4.5  4.5.6,  arithmetic  operator  3.5.5  4.5,
  3043. assignment  5.2,  attribute  4.1.4,  base  type 3.3, basic operation 3.3.3,
  3044. binary adding operator 4.5 4.5.3, bound of a  range  3.5,  constraint  3.3,
  3045. conversion  4.6,  digit  2.1,  exponentiating  operator 4.5 4.5.6, floating
  3046. point  type  3.5.7,  membership  test  4.5  4.5.2,  model   number   3.5.6,
  3047. multiplying  operator  4.5  4.5.5,  numeric type 3.5, object 3.2, operation
  3048. 3.3, predefined operator 4.5, qualified expression 4.7, relational operator
  3049. 4.5 4.5.2, safe number 3.5.6, subtype 3.3, type 3.3, unary adding  operator
  3050. 4.5   4.5.4,   universal   type   4.10,   universal_integer   type   3.5.4,
  3051. universal_real type 3.5.6
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057.  
  3058.  
  3059.  
  3060.  
  3061.  
  3062.  
  3063.  
  3064.  
  3065.  
  3066.  
  3067.  
  3068.  
  3069.  
  3070.  
  3071.  
  3072.  
  3073.  
  3074.  
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.                                   3 - 46
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108. 3.5.9  Fixed Point Types
  3109.  
  3110.  
  3111. For fixed point types, the error bound is specified as an  absolute  value,
  3112. called the delta of the fixed point type.
  3113.  
  3114.     fixed_point_constraint ::=
  3115.        fixed_accuracy_definition [range_constraint]
  3116.  
  3117.     fixed_accuracy_definition ::=  delta static_simple_expression
  3118.  
  3119. The  delta is specified by the value of the static simple expression of the
  3120. fixed accuracy definition.  This value must belong to some  real  type  and
  3121. must  be  positive  (nonzero).   If the fixed point constraint is used as a
  3122. real type definition, then it must include a range constraint;  each  bound
  3123. of  the specified range must be defined by a static expression of some real
  3124. type but the two bounds need not have the same real  type.   If  the  fixed
  3125. point  constraint  is used in a subtype indication, the range constraint is
  3126. optional.
  3127.  
  3128. A canonical form is defined for any fixed point  model  number  other  than
  3129. zero.   In  this  form:   sign  is either +1 or -1;  mantissa is a positive
  3130. (nonzero) integer;  and any  model  number  is  a  multiple  of  a  certain
  3131. positive real number called small, as follows:
  3132.  
  3133.     sign * mantissa * small
  3134.  
  3135. For the model numbers defined by a fixed point constraint, the number small
  3136. is chosen as the largest power of two that is not greater than the delta of
  3137. the  fixed  accuracy  definition.  Alternatively, it is possible to specify
  3138. the value of small by a length clause  (see  13.2),  in  which  case  model
  3139. numbers  are  multiples  of  the  specified  value.  The guaranteed minimum
  3140. accuracy of operations of a fixed point type is defined  in  terms  of  the
  3141. model  numbers  of  the fixed point constraint that forms the corresponding
  3142. real type definition (see 4.5.7).
  3143.  
  3144. For a fixed point constraint that includes a range  constraint,  the  model
  3145. numbers  comprise  zero  and  all  multiples of small whose mantissa can be
  3146. expressed using exactly B binary digits, where the value of B is chosen  as
  3147. the  smallest integer number for which each bound of the specified range is
  3148. either a model number or lies at most small distant from  a  model  number.
  3149. For a fixed point constraint that does not include a range constraint (this
  3150. is  only  allowed  after  a  type mark, in a subtype indication), the model
  3151. numbers are defined by the delta of the fixed accuracy  definition  and  by
  3152. the range of the subtype denoted by the type mark.
  3153.  
  3154. An  implementation  must have at least one anonymous predefined fixed point
  3155. type.  The base type of each such fixed point type is the type itself.  The
  3156. model numbers of each predefined fixed point type  comprise  zero  and  all
  3157. numbers for which mantissa (in the canonical form) has the number of binary
  3158. digits  returned  by the attribute MANTISSA, and for which the number small
  3159. has the value returned by the attribute SMALL.
  3160.  
  3161. A fixed point type declaration of the form:
  3162.  
  3163.  
  3164.  
  3165.                                   3 - 47
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174.     type T is delta D range L .. R;
  3175.  
  3176. is, by definition, equivalent to the following declarations:
  3177.  
  3178.     type fixed_point_type is new predefined_fixed_point_type;
  3179.     subtype T is fixed_point_type
  3180.        range fixed_point_type(L) .. fixed_point_type(R);
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187.  
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.  
  3205.  
  3206.  
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.                                   3 - 48
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240. In these declarations, fixed_point_type  is  an  anonymous  type,  and  the
  3241. predefined fixed point type is implicitly selected by the implementation so
  3242. that its model numbers include the model numbers defined by the fixed point
  3243. constraint  (that  is,  by  D,  L,  and  R, and possibly by a length clause
  3244. specifying small).
  3245.  
  3246. The fixed point declaration is illegal  if  no  predefined  type  satisfies
  3247. these  requirements.   The safe numbers of a fixed point type are the model
  3248. numbers of its base type.
  3249.  
  3250. The  elaboration  of  a  fixed  point  type  declaration  consists  of  the
  3251. elaboration of the equivalent type and subtype declarations.
  3252.  
  3253. If  the fixed point constraint follows a type mark in a subtype indication,
  3254. the type mark must denote a fixed point type or subtype.  The  fixed  point
  3255. constraint  is compatible with the type mark only if the delta specified by
  3256. the fixed accuracy definition is not smaller than the delta for the type or
  3257. subtype denoted  by  the  type  mark.   Furthermore,  if  the  fixed  point
  3258. constraint  includes  a  range  constraint,  the  fixed point constraint is
  3259. compatible with the type mark only if  the  range  constraint  is,  itself,
  3260. compatible with the type mark.
  3261.  
  3262. The  elaboration  of  such a subtype indication includes the elaboration of
  3263. the range constraint, if there is one;  it creates a  fixed  point  subtype
  3264. whose model numbers are defined by the corresponding fixed point constraint
  3265. and  also  by the length clause specifying small, if there is one.  A value
  3266. of a fixed point type belongs to a fixed point subtype if and  only  if  it
  3267. belongs to the range defined by the subtype.
  3268.  
  3269. The same arithmetic operators are predefined for all fixed point types (see
  3270. 4.5).  Multiplication and division of fixed point values deliver results of
  3271. an  anonymous predefined fixed point type that is called universal_fixed in
  3272. this reference manual;  the accuracy of this type is arbitrarily fine.  The
  3273. values of this type must be converted explicitly to some numeric type.
  3274.  
  3275. Notes:
  3276.  
  3277. If S is a subtype of a fixed point type or subtype T, then the set of model
  3278. numbers of S is a subset of those of T.  If a length clause has been  given
  3279. for  T,  then both S and T have the same value for small.  Otherwise, since
  3280. small is a power of two, the small  of  S  is  equal  to  the  small  of  T
  3281. multiplied by a nonnegative power of two.
  3282.  
  3283. A  range  constraint is allowed in a fixed point subtype indication, either
  3284. directly after the type mark, or as part of a fixed point  constraint.   In
  3285. either  case  the  bounds  of the range must belong to the base type of the
  3286. type mark (see 3.5).
  3287.  
  3288. Examples:
  3289.  
  3290.     type VOLT is delta 0.125 range 0.0 .. 255.0;
  3291.     subtype ROUGH_VOLTAGE is VOLT delta 1.0;  --  same range as VOLT
  3292.  
  3293.     --  A pure fraction which requires all the available space in a word
  3294.     --  on a two's complement machine can be declared as the type FRACTION:
  3295.  
  3296.  
  3297.                                   3 - 49
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.     DEL : constant := 1.0/2**(WORD_LENGTH - 1);
  3307.     type FRACTION is delta DEL range -1.0 .. 1.0 - DEL;
  3308.  
  3309. References:  anonymous type 3.3.1, arithmetic operator 3.5.5 4.5, base type
  3310. 3.3, belong to a subtype 3.3, bound  of  a  range  3.5,  compatible  3.3.2,
  3311. conversion  4.6,  elaboration  3.9,  error bound 3.5.6, length clause 13.2,
  3312. model number 3.5.6, numeric type 3.5, operation  3.3,  predefined  operator
  3313. 4.5,  range  constraint  3.5,  real type 3.5.6, real type definition 3.5.6,
  3314. safe number 3.5.6, simple expression 4.4, static  expression  4.9,  subtype
  3315. 3.3,  subtype  declaration  3.3.2, subtype indication 3.3.2, type 3.3, type
  3316. declaration 3.3.1, type mark 3.3.2
  3317.  
  3318.  
  3319.  
  3320.  
  3321.  
  3322.  
  3323.  
  3324.  
  3325.  
  3326.  
  3327.  
  3328.  
  3329.  
  3330.  
  3331.  
  3332.  
  3333.  
  3334.  
  3335.  
  3336.  
  3337.  
  3338.  
  3339.  
  3340.  
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.                                   3 - 50
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372. 3.5.10  Operations of Fixed Point Types
  3373.  
  3374.  
  3375. The basic operations of a fixed point type include the operations  involved
  3376. in  assignment, membership tests, qualification, the explicit conversion of
  3377. values of other numeric types to the fixed point  type,  and  the  implicit
  3378. conversion of values of the type universal_real to the type.
  3379.  
  3380. In  addition,  for every fixed point type or subtype T the basic operations
  3381. include the attributes listed below.  In this presentation T is referred to
  3382. as being a subtype (the  subtype  T)  for  any  property  that  depends  on
  3383. constraints imposed by T;  other properties are stated in terms of the base
  3384. type of T.
  3385.  
  3386. The  first group of attributes yield characteristics of the subtype T.  The
  3387. attributes  of  this  group  are  the  attributes  BASE  (see  3.3.2),  the
  3388. attributes FIRST and LAST (see 3.5), the representation attribute SIZE (see
  3389. 13.7.2) and the following attributes:
  3390.  
  3391. T'DELTA      Yields the value of the delta specified in the fixed  accuracy
  3392.              definition  for the subtype T.  The value of this attribute is
  3393.              of the type universal_real.
  3394.  
  3395. T'MANTISSA   Yields the number of binary digits in the  mantissa  of  model
  3396.              numbers of the subtype T.  (This attribute yields the number B
  3397.              of section 3.5.9.)  The value of this attribute is of the type
  3398.              universal_integer.
  3399.  
  3400. T'SMALL      Yields the smallest positive (nonzero)  model  number  of  the
  3401.              subtype  T.   The  value  of  this  attribute  is  of the type
  3402.              universal_real.
  3403.  
  3404. T'LARGE      Yields the largest positive model number  of  the  subtype  T.
  3405.              The value of this attribute is of the type universal_real.
  3406.  
  3407. T'FORE       Yields the minimum number of characters needed for the integer
  3408.              part of the decimal representation of any value of the subtype
  3409.              T,  assuming  that  the  representation  does  not  include an
  3410.              exponent, but includes a one-character prefix that is either a
  3411.              minus sign or a space.  (This minimum number does not  include
  3412.              superfluous  zeros  or  underlines, and is at least two.)  The
  3413.              value of this attribute is of the type universal_integer.
  3414.  
  3415. T'AFT        Yields the number of decimal digits needed after the point  to
  3416.              accommodate  the  precision of the subtype T, unless the delta
  3417.              of the subtype T is  greater  than  0.1,  in  which  case  the
  3418.              attribute  yields  the  value  one.   (T'AFT  is  the smallest
  3419.              positive integer N for which (10**N)*T'DELTA is  greater  than
  3420.              or  equal to one.)  The value of this attribute is of the type
  3421.              universal_integer.
  3422.  
  3423. The attributes of the second group include the following  attributes  which
  3424. yield characteristics of the safe numbers:
  3425.  
  3426.  
  3427.  
  3428.  
  3429.                                   3 - 51
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438. T'SAFE_SMALL Yields the smallest positive (nonzero) safe number of the base
  3439.              type  of  T.   The  value  of  this  attribute  is of the type
  3440.              universal_real.
  3441.  
  3442. T'SAFE_LARGE Yields the largest positive safe number of the base type of T.
  3443.              The value of this attribute is of the type universal_real.
  3444.  
  3445. In addition, the attributes A'SIZE and A'ADDRESS are defined for an  object
  3446. A  of  a fixed point type (see 13.7.2).  Finally, for each fixed point type
  3447. or subtype T, there are the machine-dependent  attributes  T'MACHINE_ROUNDS
  3448. and T'MACHINE_OVERFLOWS (see 13.7.3).
  3449.  
  3450.  
  3451.  
  3452.  
  3453.  
  3454.  
  3455.  
  3456.  
  3457.  
  3458.  
  3459.  
  3460.  
  3461.  
  3462.  
  3463.  
  3464.  
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476.  
  3477.  
  3478.  
  3479.  
  3480.  
  3481.  
  3482.  
  3483.  
  3484.  
  3485.  
  3486.  
  3487.  
  3488.  
  3489.  
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.                                   3 - 52
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504. Besides  the basic operations, the operations of a fixed point type include
  3505. the  relational  operators,  and  the   following   predefined   arithmetic
  3506. operators:   the binary and unary adding operators - and +, the multiplying
  3507. operators * and /, and the operator abs.
  3508.  
  3509. The operations of a subtype are the corresponding operations  of  the  type
  3510. except  for  the  following:   assignment, membership tests, qualification,
  3511. explicit conversion, and the attributes of the first group;  the effects of
  3512. these operations are redefined in terms of the subtype.
  3513.  
  3514. Notes:
  3515.  
  3516. The value of the attribute T'FORE depends only on the range of the  subtype
  3517. T.   The value of the attribute T'AFT depends only on the value of T'DELTA.
  3518. The following relations exist between attributes of a fixed point type:
  3519.  
  3520.     T'LARGE      = (2**T'MANTISSA - 1) * T'SMALL
  3521.     T'SAFE_LARGE = T'BASE'LARGE
  3522.     T'SAFE_SMALL = T'BASE'SMALL
  3523.  
  3524. References:   abs  operator  4.5  4.5.6,  arithmetic  operator  3.5.5  4.5,
  3525. assignment  5.2,  base  type  3.3,  basic  operation  3.3.3,  binary adding
  3526. operator 4.5 4.5.3, bound of a range  3.5,  conversion  4.6,  delta  3.5.9,
  3527. fixed  point  type  3.5.9,  membership  test 4.5 4.5.2, model number 3.5.6,
  3528. multiplying operator 4.5 4.5.5, numeric type  3.5,  object  3.2,  operation
  3529. 3.3,  qualified  expression 4.7, relational operator 4.5 4.5.2, safe number
  3530. 3.5.6, subtype 3.3, unary adding operator 4.5 4.5.4, universal_integer type
  3531. 3.5.4, universal_real type 3.5.6
  3532.  
  3533.  
  3534.  
  3535. 3.6  Array Types
  3536.  
  3537.  
  3538. An array object is a composite object consisting of  components  that  have
  3539. the  same  subtype.   The name for a component of an array uses one or more
  3540. index values belonging to specified discrete types.  The value of an  array
  3541. object is a composite value consisting of the values of its components.
  3542.  
  3543.     array_type_definition ::=
  3544.        unconstrained_array_definition | constrained_array_definition
  3545.  
  3546.     unconstrained_array_definition ::=
  3547.        array(index_subtype_definition {, index_subtype_definition}) of
  3548.                 component_subtype_indication
  3549.  
  3550.     constrained_array_definition ::=
  3551.        array index_constraint of component_subtype_indication
  3552.  
  3553.     index_subtype_definition ::= type_mark range <>
  3554.  
  3555.     index_constraint ::=  (discrete_range {, discrete_range})
  3556.  
  3557.     discrete_range ::= discrete_subtype_indication | range
  3558.  
  3559.  
  3560.  
  3561.                                   3 - 53
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570. An   array   object   is  characterized  by  the  number  of  indices  (the
  3571. dimensionality of the array), the type and  position  of  each  index,  the
  3572. lower and upper bounds for each index, and the type and possible constraint
  3573. of the components.  The order of the indices is significant.
  3574.  
  3575.  
  3576.  
  3577.  
  3578.  
  3579.  
  3580.  
  3581.  
  3582.  
  3583.  
  3584.  
  3585.  
  3586.  
  3587.  
  3588.  
  3589.  
  3590.  
  3591.  
  3592.  
  3593.  
  3594.  
  3595.  
  3596.  
  3597.  
  3598.  
  3599.  
  3600.  
  3601.  
  3602.  
  3603.  
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.                                   3 - 54
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636. A  one-dimensional  array  has a distinct component for each possible index
  3637. value.  A multidimensional array has a distinct component for each possible
  3638. sequence of index values that can be formed by  selecting   one  value  for
  3639. each  index position (in the given order).  The possible values for a given
  3640. index are all the values between the lower  and  upper  bounds,  inclusive;
  3641. this range of values is called the index range.
  3642.  
  3643. An  unconstrained  array definition defines an array type.  For each object
  3644. that has the array type, the number of indices, the type  and  position  of
  3645. each  index,  and  the  subtype  of  the  components  are  as  in  the type
  3646. definition;  the values of the lower and upper bounds for each index belong
  3647. to the corresponding index subtype, except for null arrays as explained  in
  3648. section  3.6.1.   The  index  subtype  for  a  given  index position is, by
  3649. definition, the subtype denoted by the type mark of the corresponding index
  3650. subtype definition.  The compound delimiter <> (called a box) of  an  index
  3651. subtype  definition stands for an undefined range (different objects of the
  3652. type need not have the same bounds).  The elaboration of  an  unconstrained
  3653. array  definition creates an array type;  this elaboration includes that of
  3654. the component subtype indication.
  3655.  
  3656. A constrained array definition defines both an array type and a subtype  of
  3657. this type:
  3658.  
  3659.   -  The array type is an implicitly declared anonymous type;  this type is
  3660.      defined  by an (implicit) unconstrained array definition, in which the
  3661.      component  subtype  indication  is  that  of  the  constrained   array
  3662.      definition,  and  in  which  the  type  mark  of  each  index  subtype
  3663.      definition denotes the subtype defined by the  corresponding  discrete
  3664.      range.
  3665.  
  3666.   -  The array subtype is the subtype obtained by imposition of  the  index
  3667.      constraint on the array type.
  3668.  
  3669. If  a  constrained  array  definition  is given for a type declaration, the
  3670. simple name declared by this declaration denotes the array subtype.
  3671.  
  3672. The elaboration of a constrained array definition creates the corresponding
  3673. array type and array subtype.  For this elaboration, the  index  constraint
  3674. and  the  component  subtype  indication are elaborated.  The evaluation of
  3675. each discrete range of the index constraint  and  the  elaboration  of  the
  3676. component  subtype  indication  are  performed  in  some  order that is not
  3677. defined by the language.
  3678.  
  3679. Examples of type declarations with unconstrained array definitions:
  3680.  
  3681.     type VECTOR     is array(INTEGER  range <>) of REAL;
  3682.     type MATRIX     is array(INTEGER  range <>, INTEGER range <>) of REAL;
  3683.     type BIT_VECTOR is array(INTEGER  range <>) of BOOLEAN;
  3684.     type ROMAN      is array(POSITIVE range <>) of ROMAN_DIGIT;
  3685.  
  3686. Examples of type declarations with constrained array definitions:
  3687.  
  3688.     type TABLE    is array(1 .. 10) of INTEGER;
  3689.     type SCHEDULE is array(DAY) of BOOLEAN;
  3690.     type LINE     is array(1 .. MAX_LINE_SIZE) of CHARACTER;
  3691.  
  3692.  
  3693.                                   3 - 55
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702. Examples of object declarations with constrained array definitions:
  3703.  
  3704.     GRID : array(1 .. 80, 1 .. 100) of BOOLEAN;
  3705.     MIX  : array(COLOR range RED .. GREEN) of BOOLEAN;
  3706.     PAGE : array(1 .. 50) of LINE;  --  an array of arrays
  3707.  
  3708.  
  3709.  
  3710.  
  3711.  
  3712.  
  3713.  
  3714.  
  3715.  
  3716.  
  3717.  
  3718.  
  3719.  
  3720.  
  3721.  
  3722.  
  3723.  
  3724.  
  3725.  
  3726.  
  3727.  
  3728.  
  3729.  
  3730.  
  3731.  
  3732.  
  3733.  
  3734.  
  3735.  
  3736.  
  3737.  
  3738.  
  3739.  
  3740.  
  3741.  
  3742.  
  3743.  
  3744.  
  3745.  
  3746.  
  3747.  
  3748.  
  3749.  
  3750.  
  3751.  
  3752.  
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.                                   3 - 56
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768. Note:
  3769.  
  3770. For a one-dimensional array, the rule given means that a  type  declaration
  3771. with a constrained array definition such as
  3772.  
  3773.     type T is array(POSITIVE range MIN .. MAX) of COMPONENT;
  3774.  
  3775. is  equivalent  (in  the  absence  of an incorrect order dependence) to the
  3776. succession of declarations
  3777.  
  3778.     subtype INDEX_SUBTYPE is POSITIVE range MIN .. MAX;
  3779.     type ARRAY_TYPE is array(INDEX_SUBTYPE range <>) of COMPONENT;
  3780.     subtype T is ARRAY_TYPE(INDEX_SUBTYPE);
  3781.  
  3782. where index_subtype and array_type are both anonymous.  Consequently, T  is
  3783. the  name  of  a  subtype  and all objects declared with this type mark are
  3784. arrays that  have  the  same  bounds.   Similar  transformations  apply  to
  3785. multidimensional arrays.
  3786.  
  3787. A  similar transformation applies to an object whose declaration includes a
  3788. constrained array definition.  A consequence of this is that  no  two  such
  3789. objects have the same type.
  3790.  
  3791. References:   anonymous  type  3.3.1,  bound of a range 3.5, component 3.3,
  3792. constraint 3.3, discrete type 3.5, elaboration 3.1 3.9, in some order  1.6,
  3793. name  4.1,  object  3.2,  range 3.5, subtype 3.3, subtype indication 3.3.2,
  3794. type 3.3, type declaration 3.3.1, type definition 3.3.1, type mark 3.3.2
  3795.  
  3796.  
  3797.  
  3798. 3.6.1  Index Constraints and Discrete Ranges
  3799.  
  3800.  
  3801. An index constraint determines the range of possible values for every index
  3802. of an array type, and thereby the corresponding array bounds.
  3803.  
  3804. For a discrete range used in a constrained array definition and defined  by
  3805. a  range,  an implicit conversion to the predefined type INTEGER is assumed
  3806. if each bound is either a numeric literal, a named number, or an attribute,
  3807. and the type of both bounds (prior to the implicit conversion) is the  type
  3808. universal_integer.   Otherwise,  both  bounds  must be of the same discrete
  3809. type,  other  than  universal_integer;   this  type  must  be  determinable
  3810. independently  of  the  context,  but  using the fact that the type must be
  3811. discrete and that both bounds must have the same type.  These  rules  apply
  3812. also  to  a  discrete  range  used in an iteration rule (see 5.5) or in the
  3813. declaration of a family of entries (see 9.5).
  3814.  
  3815. If an index constraint follows a type mark in a  subtype  indication,  then
  3816. the  type  or  subtype  denoted by the type mark must not already impose an
  3817. index constraint.  The type mark must denote either an unconstrained  array
  3818. type  or  an  access  type whose designated type is such an array type.  In
  3819. either case, the index constraint must provide a discrete  range  for  each
  3820. index  of  the  array  type and the type of each discrete range must be the
  3821. same as that of the corresponding index.
  3822.  
  3823.  
  3824.  
  3825.                                   3 - 57
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834. An index constraint is compatible with the type denoted by the type mark if
  3835. and only if the constraint defined by each  discrete  range  is  compatible
  3836. with  the  corresponding  index  subtype.   If  any  of the discrete ranges
  3837. defines a null range, any array thus constrained is a null array, having no
  3838. components.  An array value satisfies an index constraint if at each  index
  3839. position  the  array  value  and  the  index constraint have the same index
  3840. bounds.  (Note,  however, that assignment and certain other  operations  on
  3841. arrays involve an implicit subtype conversion.)
  3842.  
  3843.  
  3844.  
  3845.  
  3846.  
  3847.  
  3848.  
  3849.  
  3850.  
  3851.  
  3852.  
  3853.  
  3854.  
  3855.  
  3856.  
  3857.  
  3858.  
  3859.  
  3860.  
  3861.  
  3862.  
  3863.  
  3864.  
  3865.  
  3866.  
  3867.  
  3868.  
  3869.  
  3870.  
  3871.  
  3872.  
  3873.  
  3874.  
  3875.  
  3876.  
  3877.  
  3878.  
  3879.  
  3880.  
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.                                   3 - 58
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900. The bounds of each array object are determined as follows:
  3901.  
  3902.   -  For  a  variable  declared  by  an  object  declaration,  the  subtype
  3903.      indication  of  the  corresponding  object  declaration  must define a
  3904.      constrained array  subtype  (and,  thereby,  the  bounds).   The  same
  3905.      requirement   exists   for  the  subtype  indication  of  a  component
  3906.      declaration, if the type of the record component  is  an  array  type;
  3907.      and  for the component subtype indication of an array type definition,
  3908.      if the type of the array components is itself an array type.
  3909.  
  3910.   -  For a constant declared by an object declaration, the  bounds  of  the
  3911.      constant  are  defined  by  the  initial  value  if the subtype of the
  3912.      constant is unconstrained;  they are otherwise defined by this subtype
  3913.      (in the latter case, the initial value is the result  of  an  implicit
  3914.      subtype  conversion).   The  same  rule  applies  to  a generic formal
  3915.      parameter of mode in.
  3916.  
  3917.   -  For an array object designated by an access value, the bounds must  be
  3918.      defined  by  the  allocator  that  creates  the  array  object.   (The
  3919.      allocated object is constrained with the corresponding values  of  the
  3920.      bounds.)
  3921.  
  3922.   -  For a formal parameter of  a  subprogram  or  entry,  the  bounds  are
  3923.      obtained   from  the  corresponding  actual  parameter.   (The  formal
  3924.      parameter is constrained with the corresponding values of the bounds.)
  3925.  
  3926.   -  For a renaming declaration and for a generic formal parameter of  mode
  3927.      in  out,  the  bounds  are  those  of  the  renamed  object  or of the
  3928.      corresponding generic actual parameter.
  3929.  
  3930. For the elaboration  of  an  index  constraint,  the  discrete  ranges  are
  3931. evaluated in some order that is not defined by the language.
  3932.  
  3933. Examples of array declarations including an index constraint:
  3934.  
  3935.     BOARD     : MATRIX(1 .. 8,  1 .. 8);  --  see 3.6
  3936.     RECTANGLE : MATRIX(1 .. 20, 1 .. 30);
  3937.     INVERSE   : MATRIX(1 .. N,  1 .. N);  --  N need not be static
  3938.  
  3939.     FILTER    : BIT_VECTOR(0 .. 31);
  3940.  
  3941. Example of array declaration with a constrained array subtype:
  3942.  
  3943.     MY_SCHEDULE : SCHEDULE;  --  all arrays of type SCHEDULE have the same bounds
  3944.  
  3945. Example of record type with a component that is an array:
  3946.  
  3947.     type VAR_LINE(LENGTH : INTEGER) is
  3948.        record
  3949.           IMAGE : STRING(1 .. LENGTH);
  3950.        end record;
  3951.  
  3952.     NULL_LINE : VAR_LINE(0);  --  NULL_LINE.IMAGE is a null array
  3953.  
  3954.  
  3955.  
  3956.  
  3957.                                   3 - 59
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  
  3965.  
  3966. Notes:
  3967.  
  3968. The  elaboration of a subtype indication consisting of a type mark followed
  3969. by an index constraint checks the compatibility  of  the  index  constraint
  3970. with the type mark (see 3.3.2).
  3971.  
  3972. All  components  of  an array have the same subtype.  In particular, for an
  3973. array of components that are one-dimensional arrays, this  means  that  all
  3974. components have the same  bounds and hence the same length.
  3975.  
  3976.  
  3977.  
  3978.  
  3979.  
  3980.  
  3981.  
  3982.  
  3983.  
  3984.  
  3985.  
  3986.  
  3987.  
  3988.  
  3989.  
  3990.  
  3991.  
  3992.  
  3993.  
  3994.  
  3995.  
  3996.  
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.  
  4003.  
  4004.  
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.                                   3 - 60
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032. References:  access type 3.8, access type definition 3.8, access value 3.8,
  4033. actual  parameter  6.4.1,  allocator  4.8, array bound 3.6, array component
  4034. 3.6, array type 3.6, array type definition  3.6,  bound  of  a  range  3.5,
  4035. compatible  3.3.2,  component  declaration 3.7, constant 3.2.1, constrained
  4036. array definition  3.6,  constrained  array  subtype  3.6,  conversion  4.6,
  4037. designate  3.8,  designated  type 3.8, discrete range 3.6, entry 9.5, entry
  4038. family declaration 9.5, expression 4.4, formal parameter 6.1, function 6.5,
  4039. generic actual parameter 12.3, generic formal parameter 12.1 12.3,  generic
  4040. parameter  12.1,  index  3.6,  index  constraint  3.6.1, index subtype 3.6,
  4041. initial value 3.2.1, integer literal 2.4,  integer  type  3.5.4,  iteration
  4042. rule  5.5,  mode  12.1.1,  name  4.1,  null  range  3.5, object 3.2, object
  4043. declaration 3.2.1, predefined type C,  range  3.5,  record  component  3.7,
  4044. renaming  declaration  8.5,  result subtype 6.1, satisfy 3.3, subprogram 6,
  4045. subtype  conversion  4.6,  subtype  indication  3.3.2,  type  mark   3.3.2,
  4046. unconstrained  array  type  3.6,  unconstrained subtype 3.3, universal type
  4047. 4.10, universal_integer type 3.5.4, variable 3.2.1
  4048.  
  4049.  
  4050.  
  4051. 3.6.2  Operations of Array Types
  4052.  
  4053.  
  4054. The basic operations of an array type include the  operations  involved  in
  4055. assignment  and  aggregates  (unless the array type is limited), membership
  4056. tests, indexed components, qualification,  and  explicit  conversion;   for
  4057. one-dimensional  arrays  the  basic  operations also include the operations
  4058. involved in slices, and also string literals if the  component  type  is  a
  4059. character type.
  4060.  
  4061. If  A  is  an array object, an array value, or a constrained array subtype,
  4062. the basic operations also  include  the  attributes  listed  below.   These
  4063. attributes are not allowed for an unconstrained array type.  The argument N
  4064. used  in  the attribute designators for the N-th dimension of an array must
  4065. be a static expression of type universal_integer.  The value of N  must  be
  4066. positive (nonzero) and no greater than the dimensionality of the array.
  4067.  
  4068. A'FIRST         Yields the lower bound of the first index range.  The value
  4069.                 of this attribute has the same type as this lower bound.
  4070.  
  4071. A'FIRST(N)      Yields the lower bound of the N-th index range.  The  value
  4072.                 of this attribute has the same type as this lower bound.
  4073.  
  4074. A'LAST          Yields the upper bound of the first index range.  The value
  4075.                 of this attribute has the same type as this upper bound.
  4076.  
  4077. A'LAST(N)       Yields the upper bound of the N-th index range.  The  value
  4078.                 of this attribute has the same type as this upper bound.
  4079.  
  4080. A'RANGE         Yields the first index range, that is, the range A'FIRST ..
  4081.                 A'LAST.
  4082.  
  4083. A'RANGE(N)      Yields the N-th index range, that is, the range  A'FIRST(N)
  4084.                 .. A'LAST(N).
  4085.  
  4086.  
  4087.  
  4088.  
  4089.                                   3 - 61
  4090.  
  4091.  
  4092.  
  4093.  
  4094.  
  4095.  
  4096.  
  4097.  
  4098. A'LENGTH        Yields the number of values of the first index range  (zero
  4099.                 for  a  null range).  The value of this attribute is of the
  4100.                 type universal_integer.
  4101.  
  4102. A'LENGTH(N)     Yields the number of values of the N-th index  range  (zero
  4103.                 for  a  null range).  The value of this attribute is of the
  4104.                 type universal_integer.
  4105.  
  4106. In addition, the attribute T'BASE is defined for an array type or subtype T
  4107. (see 3.3.3);  the attribute T'SIZE is defined for an array type or  subtype
  4108. T,  and the attributes A'SIZE and A'ADDRESS are defined for an array object
  4109. A (see 13.7.2).
  4110.  
  4111.  
  4112.  
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.  
  4119.  
  4120.  
  4121.  
  4122.  
  4123.  
  4124.  
  4125.  
  4126.  
  4127.  
  4128.  
  4129.  
  4130.  
  4131.  
  4132.  
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.  
  4139.  
  4140.  
  4141.  
  4142.  
  4143.  
  4144.  
  4145.  
  4146.  
  4147.  
  4148.  
  4149.  
  4150.  
  4151.  
  4152.  
  4153.  
  4154.  
  4155.                                   3 - 62
  4156.  
  4157.  
  4158.  
  4159.  
  4160.  
  4161.  
  4162.  
  4163.  
  4164. Besides the basic operations, the operations of an array type  include  the
  4165. predefined comparison for equality and inequality, unless the array type is
  4166. limited.   For  one-dimensional  arrays, the operations include catenation,
  4167. unless the array type is limited;  if the  component  type  is  a  discrete
  4168. type,  the operations also include all predefined relational operators;  if
  4169. the component type is a boolean type, then the operations also include  the
  4170. unary logical negation operator not, and the logical operators.
  4171.  
  4172. Examples (using arrays declared in the examples of section 3.6.1):
  4173.  
  4174.     --  FILTER'FIRST       =    0   FILTER'LAST        =  31   FILTER'LENGTH  =  32
  4175.     --  RECTANGLE'LAST(1)  =   20   RECTANGLE'LAST(2)  =  30
  4176.  
  4177. Notes:
  4178.  
  4179. The  attributes  A'FIRST  and  A'FIRST(1)  yield the same value.  A similar
  4180. relation exists for the attributes  A'LAST,  A'RANGE,  and  A'LENGTH.   The
  4181. following  relations  are  satisfied (except for a null array) by the above
  4182. attributes if the index type is an integer type:
  4183.  
  4184.     A'LENGTH    = A'LAST    - A'FIRST    + 1
  4185.     A'LENGTH(N) = A'LAST(N) - A'FIRST(N) + 1
  4186.  
  4187. An array type is limited if its component type is limited (see 7.4.4).
  4188.  
  4189. References:  aggregate 4.3,  array  type  3.6,  assignment  5.2,  attribute
  4190. 4.1.4, basic operation 3.3.3, bound of a range 3.5, catenation operator 4.5
  4191. 4.5.3, character type 3.5.2, constrained array subtype 3.6, conversion 4.6,
  4192. designator  6.1, dimension 3.6, index 3.6, indexed component 4.1.1, limited
  4193. type 7.4.4, logical operator 4.5 4.5.1,  membership  test  4.5  4.5.2,  not
  4194. operator  4.5  4.5.6, null range 3.5, object 3.2, operation 3.3, predefined
  4195. operator 4.5, qualified expression  4.7,  relational  operator  4.5  4.5.2,
  4196. slice  4.1.2,  static expression 4.9, string literal 2.6, subcomponent 3.3,
  4197. type  3.3,   unconstrained   array   type   3.6,   universal   type   4.10,
  4198. universal_integer type 3.5.4
  4199.  
  4200.  
  4201.  
  4202. 3.6.3  The Type String
  4203.  
  4204.  
  4205. The  values of the predefined type STRING are one-dimensional arrays of the
  4206. predefined type CHARACTER, indexed by  values  of  the  predefined  subtype
  4207. POSITIVE:
  4208.  
  4209.     subtype POSITIVE is INTEGER range 1 .. INTEGER'LAST;
  4210.     type STRING is array(POSITIVE range <>) of CHARACTER;
  4211.  
  4212. Examples:
  4213.  
  4214.     STARS      : STRING(1 .. 120) := (1 .. 120 => '*' );
  4215.     QUESTION   : constant STRING  := "HOW MANY CHARACTERS?";
  4216.     --  QUESTION'FIRST = 1, QUESTION'LAST = 20 (the number of characters)
  4217.  
  4218.  
  4219.  
  4220.  
  4221.                                   3 - 63
  4222.  
  4223.  
  4224.  
  4225.  
  4226.  
  4227.  
  4228.  
  4229.  
  4230.     ASK_TWICE  : constant STRING  := QUESTION & QUESTION;
  4231.     NINETY_SIX : constant ROMAN   := "XCVI";        --  see 3.6
  4232.  
  4233. Notes:
  4234.  
  4235. String  literals  (see  2.6 and 4.2) are basic operations applicable to the
  4236. type STRING and to any other one-dimensional  array  type  whose  component
  4237. type is a character type.  The catenation operator is a predefined operator
  4238. for the type STRING and for one-dimensional array types;  it is represented
  4239. as  &.  The relational operators <, <=, >, and >= are defined for values of
  4240. these types, and correspond to lexicographic order (see 4.5.2).
  4241.  
  4242.  
  4243.  
  4244.  
  4245.  
  4246.  
  4247.  
  4248.  
  4249.  
  4250.  
  4251.  
  4252.  
  4253.  
  4254.  
  4255.  
  4256.  
  4257.  
  4258.  
  4259.  
  4260.  
  4261.  
  4262.  
  4263.  
  4264.  
  4265.  
  4266.  
  4267.  
  4268.  
  4269.  
  4270.  
  4271.  
  4272.  
  4273.  
  4274.  
  4275.  
  4276.  
  4277.  
  4278.  
  4279.  
  4280.  
  4281.  
  4282.  
  4283.  
  4284.  
  4285.  
  4286.  
  4287.                                   3 - 64
  4288.  
  4289.  
  4290.  
  4291.  
  4292.  
  4293.  
  4294.  
  4295.  
  4296. References:  aggregate 4.3,  array  3.6,  catenation  operator  4.5  4.5.3,
  4297. character  type  3.5.2,  component  type  (of an array) 3.6, dimension 3.6,
  4298. index 3.6, lexicographic order 4.5.2, positional aggregate 4.3,  predefined
  4299. operator  4.5,  predefined  type  C,  relational operator 4.5 4.5.2, string
  4300. literal 2.6, subtype 3.3, type 3.3
  4301.  
  4302.  
  4303.  
  4304. 3.7  Record Types
  4305.  
  4306.  
  4307. A record object is a composite object consisting of named components.   The
  4308. value  of  a record object is a composite value consisting of the values of
  4309. its components.
  4310.  
  4311.     record_type_definition ::=
  4312.        record
  4313.           component_list
  4314.        end record
  4315.  
  4316.     component_list ::=
  4317.           component_declaration {component_declaration}
  4318.        | {component_declaration} variant_part
  4319.        |  null;
  4320.  
  4321.     component_declaration ::=
  4322.        identifier_list : component_subtype_definition [:= expression];
  4323.  
  4324.     component_subtype_definition ::=  subtype_indication
  4325.  
  4326. Each component  declaration  declares  a  component  of  the  record  type.
  4327. Besides  components declared by component declarations, the components of a
  4328. record type include any components declared by discriminant  specifications
  4329. of  the  record  type  declaration.  The identifiers of all components of a
  4330. record type must be distinct.  The use of a  name  that  denotes  a  record
  4331. component  other  than a discriminant is not allowed within the record type
  4332. definition that declares the component.
  4333.  
  4334. A component  declaration  with  several  identifiers  is  equivalent  to  a
  4335. sequence  of  single  component  declarations, as explained in section 3.2.
  4336. Each single component declaration declares a record component whose subtype
  4337. is specified by the component subtype definition.
  4338.  
  4339. If a component  declaration  includes  the  assignment  compound  delimiter
  4340. followed  by an expression, the expression is the default expression of the
  4341. record component;  the default expression  must  be  of  the  type  of  the
  4342. component.   Default expressions are not allowed for components that are of
  4343. a limited type.
  4344.  
  4345. If a record type does not have a discriminant part, the same components are
  4346. present in all values of the type.  If the component list of a record  type
  4347. is  defined  by  the  reserved word null and there is no discriminant part,
  4348. then the record type has no components and all records of the type are null
  4349. records.
  4350.  
  4351.  
  4352.  
  4353.                                   3 - 65
  4354.  
  4355.  
  4356.  
  4357.  
  4358.  
  4359.  
  4360.  
  4361.  
  4362. The elaboration of a record type definition  creates  a  record  type;   it
  4363. consists  of  the  elaboration  of  any  corresponding  (single)  component
  4364. declarations, in the order in which they appear,  including  any  component
  4365. declaration  in a variant part.  The elaboration of a component declaration
  4366. consists of the elaboration of the component subtype definition.
  4367.  
  4368. For the elaboration of a component subtype definition,  if  the  constraint
  4369. does  not depend on a discriminant (see 3.7.1), then the subtype indication
  4370. is elaborated.  If,  on  the  other  hand,  the  constraint  depends  on  a
  4371. discriminant,  then  the  elaboration  consists  of  the  evaluation of any
  4372. included expression that is not a discriminant.
  4373.  
  4374.  
  4375.  
  4376.  
  4377.  
  4378.  
  4379.  
  4380.  
  4381.  
  4382.  
  4383.  
  4384.  
  4385.  
  4386.  
  4387.  
  4388.  
  4389.  
  4390.  
  4391.  
  4392.  
  4393.  
  4394.  
  4395.  
  4396.  
  4397.  
  4398.  
  4399.  
  4400.  
  4401.  
  4402.  
  4403.  
  4404.  
  4405.  
  4406.  
  4407.  
  4408.  
  4409.  
  4410.  
  4411.  
  4412.  
  4413.  
  4414.  
  4415.  
  4416.  
  4417.  
  4418.  
  4419.                                   3 - 66
  4420.  
  4421.  
  4422.  
  4423.  
  4424.  
  4425.  
  4426.  
  4427.  
  4428. Examples of record type declarations:
  4429.  
  4430.     type DATE is
  4431.        record
  4432.           DAY   : INTEGER range 1 .. 31;
  4433.           MONTH : MONTH_NAME;
  4434.           YEAR  : INTEGER range 0 .. 4000;
  4435.        end record;
  4436.  
  4437.     type COMPLEX is
  4438.        record
  4439.           RE : REAL := 0.0;
  4440.           IM : REAL := 0.0;
  4441.        end record;
  4442.  
  4443. Examples of record variables:
  4444.  
  4445.     TOMORROW, YESTERDAY : DATE;
  4446.     A, B, C : COMPLEX;
  4447.  
  4448.     -- both components of A, B, and C are implicitly initialized to zero
  4449.  
  4450. Notes:
  4451.  
  4452. The default expression of a record component is implicitly evaluated by the
  4453. elaboration of the declaration of a record object, in  the  absence  of  an
  4454. explicit  initialization  (see  3.2.1).   If  a  component  declaration has
  4455. several identifiers,  the  expression  is  evaluated  once  for  each  such
  4456. component  of the object (since the declaration is equivalent to a sequence
  4457. of single component declarations).
  4458.  
  4459. Unlike the components of an array, the components of a record need  not  be
  4460. of the same type.
  4461.  
  4462. References:   assignment  compound  delimiter 2.2, component 3.3, composite
  4463. value 3.3, constraint 3.3, declaration 3.1, depend on a discriminant 3.7.1,
  4464. discriminant 3.3, discriminant part 3.7 3.7.1, elaboration 3.9,  expression
  4465. 4.4,  identifier  2.3,  identifier  list 3.2, limited type 7.4.4, name 4.1,
  4466. object 3.2, subtype 3.3, type 3.3, type mark 3.3.2, variant part 3.7.3
  4467.  
  4468.  
  4469.  
  4470. 3.7.1  Discriminants
  4471.  
  4472.  
  4473. A discriminant part specifies the discriminants of a type.  A  discriminant
  4474. of  a record is a component of the record.  The type of a discriminant must
  4475. be discrete.
  4476.  
  4477.     discriminant_part ::=
  4478.        (discriminant_specification {; discriminant_specification})
  4479.  
  4480.     discriminant_specification ::=
  4481.        identifier_list : type_mark [:= expression]
  4482.  
  4483.  
  4484.  
  4485.                                   3 - 67
  4486.  
  4487.  
  4488.  
  4489.  
  4490.  
  4491.  
  4492.  
  4493.  
  4494. A discriminant part is only allowed in the type declaration  for  a  record
  4495. type,  in a private type declaration or an incomplete type declaration (the
  4496. corresponding full declaration must then declare a record type), and in the
  4497. generic parameter declaration for a formal private type.
  4498.  
  4499.  
  4500.  
  4501.  
  4502.  
  4503.  
  4504.  
  4505.  
  4506.  
  4507.  
  4508.  
  4509.  
  4510.  
  4511.  
  4512.  
  4513.  
  4514.  
  4515.  
  4516.  
  4517.  
  4518.  
  4519.  
  4520.  
  4521.  
  4522.  
  4523.  
  4524.  
  4525.  
  4526.  
  4527.  
  4528.  
  4529.  
  4530.  
  4531.  
  4532.  
  4533.  
  4534.  
  4535.  
  4536.  
  4537.  
  4538.  
  4539.  
  4540.  
  4541.  
  4542.  
  4543.  
  4544.  
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.                                   3 - 68
  4552.  
  4553.  
  4554.  
  4555.  
  4556.  
  4557.  
  4558.  
  4559.  
  4560. A discriminant specification with several identifiers is  equivalent  to  a
  4561. sequence  of  single  discriminant  specifications, as explained in section
  4562. 3.2.  Each single discriminant specification declares a discriminant.  If a
  4563. discriminant  specification  includes  the  assignment  compound  delimiter
  4564. followed  by an expression, the expression is the default expression of the
  4565. discriminant;   the  default  expression  must  be  of  the  type  of   the
  4566. discriminant.   Default  expressions must be provided either for all or for
  4567. none of the discriminants of a discriminant part.
  4568.  
  4569. The use of the name of a discriminant is not allowed in default expressions
  4570. of a discriminant part if the specification of the discriminant  is  itself
  4571. given in the discriminant part.
  4572.  
  4573. Within  a  record  type  definition  the only allowed uses of the name of a
  4574. discriminant of the record type are:  in the default expressions for record
  4575. components;  in a  variant  part  as  the  discriminant  name;   and  in  a
  4576. component  subtype definition, either as a bound in an index constraint, or
  4577. to  specify  a  discriminant  value  in  a  discriminant   constraint.    A
  4578. discriminant  name  used in these component subtype definitions must appear
  4579. by itself, not as part of a  larger  expression.   Such  component  subtype
  4580. definitions and such constraints are said to depend on a discriminant.
  4581.  
  4582. A component is said to depend on a discriminant if it is a record component
  4583. declared  in  a variant part, or a record component whose component subtype
  4584. definition depends on a discriminant, or finally, one of the  subcomponents
  4585. of a component that itself depends on a discriminant.
  4586.  
  4587. Each  record value includes a value for each discriminant specified for the
  4588. record type;  it also includes a value for each record component that  does
  4589. not  depend  on  a discriminant.  The values of the discriminants determine
  4590. which other component values are in the record value.
  4591.  
  4592. Direct  assignment  to  a  discriminant  of  an  object  is  not   allowed;
  4593. furthermore a discriminant is not allowed as an actual parameter of mode in
  4594. out  or  out,  or  as  a generic actual parameter of mode in out.  The only
  4595. allowed way to change the value of a  discriminant  of  a  variable  is  to
  4596. assign a (complete) value to the variable itself.  Similarly, an assignment
  4597. to  the variable itself is the only allowed way to change the constraint of
  4598. one of its components, if the component subtype  definition  depends  on  a
  4599. discriminant of the variable.
  4600.  
  4601. The elaboration of a discriminant part has no other effect.
  4602.  
  4603. Examples:
  4604.  
  4605.     type BUFFER(SIZE : BUFFER_SIZE := 100) is        -- see 3.5.4
  4606.        record
  4607.           POS   : BUFFER_SIZE := 0;
  4608.           VALUE : STRING(1 .. SIZE);
  4609.        end record;
  4610.  
  4611.     type SQUARE(SIDE : INTEGER) is
  4612.        record
  4613.           MAT : MATRIX(1 .. SIDE, 1 .. SIDE);       -- see 3.6
  4614.        end record;
  4615.  
  4616.  
  4617.                                   3 - 69
  4618.  
  4619.  
  4620.  
  4621.  
  4622.  
  4623.  
  4624.  
  4625.  
  4626.     type DOUBLE_SQUARE(NUMBER : INTEGER) is
  4627.        record
  4628.           LEFT  : SQUARE(NUMBER);
  4629.           RIGHT : SQUARE(NUMBER);
  4630.        end record;
  4631.  
  4632.  
  4633.  
  4634.  
  4635.  
  4636.  
  4637.  
  4638.  
  4639.  
  4640.  
  4641.  
  4642.  
  4643.  
  4644.  
  4645.  
  4646.  
  4647.  
  4648.  
  4649.  
  4650.  
  4651.  
  4652.  
  4653.  
  4654.  
  4655.  
  4656.  
  4657.  
  4658.  
  4659.  
  4660.  
  4661.  
  4662.  
  4663.  
  4664.  
  4665.  
  4666.  
  4667.  
  4668.  
  4669.  
  4670.  
  4671.  
  4672.  
  4673.  
  4674.  
  4675.  
  4676.  
  4677.  
  4678.  
  4679.  
  4680.  
  4681.  
  4682.  
  4683.                                   3 - 70
  4684.  
  4685.  
  4686.  
  4687.  
  4688.  
  4689.  
  4690.  
  4691.  
  4692.     type ITEM(NUMBER : POSITIVE) is
  4693.        record
  4694.           CONTENT : INTEGER;
  4695.           --  no component depends on the discriminant
  4696.        end record;
  4697.  
  4698. References:   assignment 5.2, assignment compound delimiter 2.2, bound of a
  4699. range 3.5, component 3.3, component declaration 3.7, component of a  record
  4700. 3.7,  declaration  3.1,  discrete  type 3.5, discriminant 3.3, discriminant
  4701. constraint 3.7.2, elaboration 3.9,  expression  4.4,  generic  formal  type
  4702. 12.1,  generic  parameter declaration 12.1, identifier 2.3, identifier list
  4703. 3.2, incomplete type declaration 3.8.1, index constraint 3.6.1,  name  4.1,
  4704. object  3.2,  private  type  7.4, private type declaration 7.4, record type
  4705. 3.7, scope 8.2, simple  name  4.1,  subcomponent  3.3,  subtype  indication
  4706. 3.3.2, type declaration 3.3.1, type mark 3.3.2, variant part 3.7.3
  4707.  
  4708.  
  4709.  
  4710.  
  4711. 3.7.2  Discriminant Constraints
  4712.  
  4713.  
  4714. A  discriminant constraint is only allowed in a subtype indication, after a
  4715. type mark.  This type mark must denote either a type with discriminants, or
  4716. an access type whose designated type  is  a  type  with  discriminants.   A
  4717. discriminant constraint specifies the values of these discriminants.
  4718.  
  4719.     discriminant_constraint ::=
  4720.        (discriminant_association {, discriminant_association})
  4721.  
  4722.     discriminant_association ::=
  4723.        [discriminant_simple_name {| discriminant_simple_name} =>] expression
  4724.  
  4725. Each  discriminant  association  associates  an expression with one or more
  4726. discriminants.  A discriminant association is  said  to  be  named  if  the
  4727. discriminants  are  specified  explicitly  by their names;  it is otherwise
  4728. said  to  be  positional.   For  a  positional  association,  the  (single)
  4729. discriminant  is implicitly specified by position, in textual order.  Named
  4730. associations can be given in any order, but if both  positional  and  named
  4731. associations  are used in the same discriminant constraint, then positional
  4732. associations must occur first, at their  normal  position.   Hence  once  a
  4733. named association is used, the rest of the discriminant constraint must use
  4734. only named associations.
  4735.  
  4736. For  a  named  discriminant association, the discriminant names must denote
  4737. discriminants of the type for which the discriminant constraint  is  given.
  4738. A  discriminant  association  with  more than one discriminant name is only
  4739. allowed if the named discriminants are all of the same type.   Furthermore,
  4740. for  each  discriminant  association  (whether  named  or  positional), the
  4741. expression and the associated discriminants must have  the  same  type.   A
  4742. discriminant   constraint   must   provide   exactly  one  value  for  each
  4743. discriminant of the type.
  4744.  
  4745. A discriminant constraint is compatible with the type  denoted  by  a  type
  4746. mark,  if and only if each discriminant value belongs to the subtype of the
  4747.  
  4748.  
  4749.                                   3 - 71
  4750.  
  4751.  
  4752.  
  4753.  
  4754.  
  4755.  
  4756.  
  4757.  
  4758. corresponding discriminant.   In  addition,  for  each  subcomponent  whose
  4759. component   subtype   specification   depends   on    a  discriminant,  the
  4760. discriminant value is substituted for the discriminant  in  this  component
  4761. subtype  specification  and  the  compatibility  of  the  resulting subtype
  4762. indication is checked.
  4763.  
  4764. A composite value satisfies a discriminant constraint if and only  if  each
  4765. discriminant   of  the  composite  value  has  the  value  imposed  by  the
  4766. discriminant constraint.
  4767.  
  4768.  
  4769.  
  4770.  
  4771.  
  4772.  
  4773.  
  4774.  
  4775.  
  4776.  
  4777.  
  4778.  
  4779.  
  4780.  
  4781.  
  4782.  
  4783.  
  4784.  
  4785.  
  4786.  
  4787.  
  4788.  
  4789.  
  4790.  
  4791.  
  4792.  
  4793.  
  4794.  
  4795.  
  4796.  
  4797.  
  4798.  
  4799.  
  4800.  
  4801.  
  4802.  
  4803.  
  4804.  
  4805.  
  4806.  
  4807.  
  4808.  
  4809.  
  4810.  
  4811.  
  4812.  
  4813.  
  4814.  
  4815.                                   3 - 72
  4816.  
  4817.  
  4818.  
  4819.  
  4820.  
  4821.  
  4822.  
  4823.  
  4824. The initial values of the  discriminants  of  an  object  of  a  type  with
  4825. discriminants are determined as follows:
  4826.  
  4827.   -  For  a  variable  declared  by  an  object  declaration,  the  subtype
  4828.      indication  of  the  corresponding  object  declaration  must impose a
  4829.      discriminant constraint  unless  default  expressions  exist  for  the
  4830.      discriminants;   the  discriminant  values  are  defined either by the
  4831.      constraint or, in its absence, by the default expressions.   The  same
  4832.      requirement   exists   for  the  subtype  indication  of  a  component
  4833.      declaration, if the type of the record  component  has  discriminants;
  4834.      and for the component subtype indication of an array type, if the type
  4835.      of the array components is a type with discriminants.
  4836.  
  4837.   -  For a constant declared by an object declaration, the  values  of  the
  4838.      discriminants  are  those  of  the initial value if the subtype of the
  4839.      constant is unconstrained;  they are otherwise defined by this subtype
  4840.      (in the latter case, an exception is raised if the initial value  does
  4841.      not  belong  to  this  subtype).   The  same rule applies to a generic
  4842.      parameter of mode in.
  4843.  
  4844.   -  For an object designated by an access value, the  discriminant  values
  4845.      must  be  defined  by  the  allocator  that  creates the object.  (The
  4846.      allocated object is constrained with  the  corresponding  discriminant
  4847.      values.)
  4848.  
  4849.   -  For a formal parameter of a subprogram or entry, the discriminants  of
  4850.      the  formal  parameter are initialized with those of the corresponding
  4851.      actual  parameter.   (The  formal  parameter  is  constrained  if  the
  4852.      corresponding  actual parameter is constrained, and in any case if the
  4853.      mode is in or if the subtype of the formal parameter is  constrained.)
  4854.  
  4855.   -  For a renaming declaration and for a generic formal parameter of  mode
  4856.      in  out,  the  discriminants are those of the renamed object or of the
  4857.      corresponding generic actual parameter.
  4858.  
  4859. For the elaboration of a discriminant constraint, the expressions given  in
  4860. the  discriminant  associations  are  evaluated  in  some order that is not
  4861. defined by  the  language;   the  expression  of  a  named  association  is
  4862. evaluated once for each named discriminant.
  4863.  
  4864. Examples (using types declared in the previous section):
  4865.  
  4866.     LARGE   : BUFFER(200);  --  constrained, always 200 characters (explicit discriminant value)
  4867.     MESSAGE : BUFFER;       --  unconstrained, initially 100 characters (default discriminant value)
  4868.  
  4869.     BASIS   : SQUARE(5);    --  constrained, always 5 by 5
  4870.     ILLEGAL : SQUARE;       --  illegal, a SQUARE must be constrained
  4871.  
  4872. Note:
  4873.  
  4874. The  above  rules  and  the  rules  defining  the  elaboration of an object
  4875. declaration (see 3.2) ensure that discriminants always have  a  value.   In
  4876. particular,   if   a  discriminant  constraint  is  imposed  on  an  object
  4877. declaration, each discriminant is initialized with the value  specified  by
  4878. the   constraint.    Similarly,  if  the  subtype  of  a  component  has  a
  4879.  
  4880.  
  4881.                                   3 - 73
  4882.  
  4883.  
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  
  4889.  
  4890. discriminant  constraint,  the   discriminants   of   the   component   are
  4891. correspondingly initialized.
  4892.  
  4893. References:  access type 3.8, access type definition 3.8, access value 3.8,
  4894. actual  parameter 6.4.1, allocator 4.8, array type definition 3.6, bound of
  4895. a range 3.5, compatible 3.3.2, component 3.3,  component  declaration  3.7,
  4896. component  subtype  indication  3.7,  composite  value 3.3, constant 3.2.1,
  4897. constrained  subtype  3.3,  constraint  3.3,   declaration   3.1,   default
  4898. expression  for  a  discriminant  3.7,  depend  on  a  discriminant  3.7.1,
  4899. designate 3.8, designated type  3.8,  discriminant  3.3,  elaboration  3.9,
  4900. entry  9.5,  evaluation  4.5, expression 4.4, formal parameter 6.1, generic
  4901. actual parameter 12.3, generic formal parameter 12.1  12.3,  mode  in  6.1,
  4902. mode  in  out 6.1, name 4.1, object 3.2, object declaration 3.2.1, renaming
  4903. declaration  8.5,  reserved  word  2.9,  satisfy  3.3,  simple  name   4.1,
  4904. subcomponent 3.3, subprogram 6, subtype 3.3, subtype indication 3.3.2, type
  4905. 3.3, type mark 3.3.2, variable 3.2.1
  4906.  
  4907.  
  4908.  
  4909.  
  4910.  
  4911.  
  4912.  
  4913.  
  4914.  
  4915.  
  4916.  
  4917.  
  4918.  
  4919.  
  4920.  
  4921.  
  4922.  
  4923.  
  4924.  
  4925.  
  4926.  
  4927.  
  4928.  
  4929.  
  4930.  
  4931.  
  4932.  
  4933.  
  4934.  
  4935.  
  4936.  
  4937.  
  4938.  
  4939.  
  4940.  
  4941.  
  4942.  
  4943.  
  4944.  
  4945.  
  4946.  
  4947.                                   3 - 74
  4948.  
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  
  4955.  
  4956. 3.7.3  Variant Parts
  4957.  
  4958.  
  4959. A   record  type  with  a  variant  part  specifies  alternative  lists  of
  4960. components.  Each variant defines  the  components  for  the  corresponding
  4961. value or values of the discriminant.
  4962.  
  4963.     variant_part ::=
  4964.        case discriminant_simple_name is
  4965.            variant
  4966.           {variant}
  4967.        end case;
  4968.  
  4969.     variant ::=
  4970.        when choice {| choice} =>
  4971.           component_list
  4972.  
  4973.     choice ::= simple_expression
  4974.        | discrete_range | others | component_simple_name
  4975.  
  4976. Each  variant  starts with a list of choices which must be of the same type
  4977. as the discriminant of the variant part.  The type of the discriminant of a
  4978. variant part must not be a generic formal type.   If  the  subtype  of  the
  4979. discriminant is static, then each value of this subtype must be represented
  4980. once  and only once in the set of choices of the variant part, and no other
  4981. value is allowed.   Otherwise,  each  value  of  the  (base)  type  of  the
  4982. discriminant  must be represented once and only once in the set of choices.
  4983.  
  4984. The simple expressions and discrete ranges given as choices  in  a  variant
  4985. part  must  be static.  A choice defined by a discrete range stands for all
  4986. values in the corresponding range (none  if  a  null  range).   The  choice
  4987. others  is  only  allowed  for the last variant and as its only choice;  it
  4988. stands for all values (possibly none) not given in the choices of  previous
  4989. variants.   A component simple name is not allowed as a choice of a variant
  4990. (although it is part of the syntax of choice).
  4991.  
  4992. A record value contains the values of the components of a given variant  if
  4993. and  only if the discriminant value is equal to one of the values specified
  4994. by the choices of the variant.  This rule applies in turn  to  any  further
  4995. variant  that  is,  itself,  included  in  the  component list of the given
  4996. variant.  If the component list of a variant  is  specified  by  null,  the
  4997. variant has no components.
  4998.  
  4999. Example of record type with a variant part:
  5000.  
  5001.     type DEVICE is (PRINTER, DISK, DRUM);
  5002.     type STATE  is (OPEN, CLOSED);
  5003.  
  5004.     type PERIPHERAL(UNIT : DEVICE := DISK) is
  5005.        record
  5006.           STATUS : STATE;
  5007.           case UNIT is
  5008.              when PRINTER =>
  5009.                 LINE_COUNT : INTEGER range 1 .. PAGE_SIZE;
  5010.              when others =>
  5011.  
  5012.  
  5013.                                   3 - 75
  5014.  
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.  
  5021.  
  5022.                 CYLINDER   : CYLINDER_INDEX;
  5023.                 TRACK      : TRACK_NUMBER;
  5024.           end case;
  5025.        end record;
  5026.  
  5027.  
  5028.  
  5029.  
  5030.  
  5031.  
  5032.  
  5033.  
  5034.  
  5035.  
  5036.  
  5037.  
  5038.  
  5039.  
  5040.  
  5041.  
  5042.  
  5043.  
  5044.  
  5045.  
  5046.  
  5047.  
  5048.  
  5049.  
  5050.  
  5051.  
  5052.  
  5053.  
  5054.  
  5055.  
  5056.  
  5057.  
  5058.  
  5059.  
  5060.  
  5061.  
  5062.  
  5063.  
  5064.  
  5065.  
  5066.  
  5067.  
  5068.  
  5069.  
  5070.  
  5071.  
  5072.  
  5073.  
  5074.  
  5075.  
  5076.  
  5077.  
  5078.  
  5079.                                   3 - 76
  5080.  
  5081.  
  5082.  
  5083.  
  5084.  
  5085.  
  5086.  
  5087.  
  5088. Examples of record subtypes:
  5089.  
  5090.     subtype DRUM_UNIT is PERIPHERAL(DRUM);
  5091.     subtype DISK_UNIT is PERIPHERAL(DISK);
  5092.  
  5093. Examples of constrained record variables:
  5094.  
  5095.     WRITER  : PERIPHERAL(UNIT => PRINTER);
  5096.     ARCHIVE : DISK_UNIT;
  5097.  
  5098. Note:
  5099.  
  5100. Choices  with discrete values are also used in case statements and in array
  5101. aggregates.  Choices  with  component  simple  names  are  used  in  record
  5102. aggregates.
  5103.  
  5104. References:  array aggregate 4.3.2, base type 3.3, component 3.3, component
  5105. list 3.7, discrete range 3.6, discriminant 3.3, generic formal type 12.1.2,
  5106. null  range 3.5, record aggregate 4.3.1, range 3.5, record type 3.7, simple
  5107. expression  4.4,  simple  name  4.1,  static  discrete  range  4.9,  static
  5108. expression 4.9, static subtype 4.9, subtype 3.3
  5109.  
  5110.  
  5111.  
  5112.  
  5113. 3.7.4  Operations of Record Types
  5114.  
  5115.  
  5116. The  basic  operations  of a record type include the operations involved in
  5117. assignment and aggregates (unless the type is limited),  membership  tests,
  5118. selection  of  record  components,  qualification, and type conversion (for
  5119. derived types).
  5120.  
  5121. For any object A of a type with discriminants, the  basic  operations  also
  5122. include the following attribute:
  5123.  
  5124. A'CONSTRAINED   Yields the value TRUE if a discriminant constraint  applies
  5125.                 to  the object A, or if the object is a constant (including
  5126.                 a formal parameter or generic formal parameter of mode in);
  5127.                 yields the value FALSE otherwise.  If A is a generic formal
  5128.                 parameter of mode in out, or if A is a formal parameter  of
  5129.                 mode  in  out  or  out  and  the  type  mark  given  in the
  5130.                 corresponding   parameter    specification    denotes    an
  5131.                 unconstrained  type  with  discriminants, then the value of
  5132.                 this attribute is obtained from that of  the  corresponding
  5133.                 actual  parameter.   The  value of this attribute is of the
  5134.                 predefined type BOOLEAN.
  5135.  
  5136. In addition, the attributes T'BASE and T'SIZE are defined for a record type
  5137. or subtype T (see 3.3.3);  the attributes A'SIZE and A'ADDRESS are  defined
  5138. for a record object A (see 13.7.2).
  5139.  
  5140. Besides  the  basic operations, the operations of a record type include the
  5141. predefined comparison for equality  and  inequality,  unless  the  type  is
  5142. limited.
  5143.  
  5144.  
  5145.                                   3 - 77
  5146.  
  5147.  
  5148.  
  5149.  
  5150.  
  5151.  
  5152.  
  5153.  
  5154. Note:
  5155.  
  5156. A  record  type  is limited if the type of any of its components is limited
  5157. (see 7.4.4).
  5158.  
  5159. References:   actual  parameter  6.4.1,  aggregate  4.3,  assignment   5.2,
  5160. attribute 4.1.4, basic operation 3.3.3, boolean type 3.5.3, constant 3.2.1,
  5161. conversion 4.6, derived type 3.4, discriminant 3.3, discriminant constraint
  5162. 3.7.2,  formal parameter 6.1, generic actual parameter 12.3, generic formal
  5163. parameter 12.1 12.3, limited type 7.4.4, membership test  4.5  4.5.2,  mode
  5164. 6.1,  object 3.2.1, operation 3.3, predefined operator 4.5, predefined type
  5165. C, qualified expression 4.7,  record  type  3.7,  relational  operator  4.5
  5166. 4.5.2, selected component 4.1.3, subcomponent 3.3, subtype 3.3, type 3.3
  5167.  
  5168.  
  5169.  
  5170.  
  5171.  
  5172.  
  5173.  
  5174.  
  5175.  
  5176.  
  5177.  
  5178.  
  5179.  
  5180.  
  5181.  
  5182.  
  5183.  
  5184.  
  5185.  
  5186.  
  5187.  
  5188.  
  5189.  
  5190.  
  5191.  
  5192.  
  5193.  
  5194.  
  5195.  
  5196.  
  5197.  
  5198.  
  5199.  
  5200.  
  5201.  
  5202.  
  5203.  
  5204.  
  5205.  
  5206.  
  5207.  
  5208.  
  5209.  
  5210.  
  5211.                                   3 - 78
  5212.  
  5213.  
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.  
  5220. 3.8  Access Types
  5221.  
  5222.  
  5223. An  object  declared by an object declaration is created by the elaboration
  5224. of the object declaration and is denoted by a simple name or by some  other
  5225. form  of  name.   In  contrast,  there  are objects that are created by the
  5226. evaluation of allocators (see 4.8) and that have no simple name.  Access to
  5227. such an object is achieved by an access value  returned  by  an  allocator;
  5228. the access value is said to designate the object.
  5229.  
  5230.     access_type_definition ::= access subtype_indication
  5231.  
  5232. For each access type, there is a literal null which has a null access value
  5233. designating  no  object  at  all.   The null value of an access type is the
  5234. default initial value of the type.  Other values  of  an  access  type  are
  5235. obtained  by  evaluation  of  a  special  operation  of the type, called an
  5236. allocator.  Each such access value designates  an  object  of  the  subtype
  5237. defined  by  the  subtype  indication  of the access type definition;  this
  5238. subtype is called the designated subtype;  the base type of this subtype is
  5239. called the designated type.  The objects designated by  the  values  of  an
  5240. access type form a collection implicitly associated with the type.
  5241.  
  5242. The elaboration of an access type definition consists of the elaboration of
  5243. the subtype indication and creates an access type.
  5244.  
  5245. If  an  access  object  is  constant,  the contained access value cannot be
  5246. changed and always designates the same object.   On  the  other  hand,  the
  5247. value  of the designated object need not remain the same (assignment to the
  5248. designated object is allowed unless the designated type is limited).
  5249.  
  5250. The only forms of constraint that are allowed after the name of  an  access
  5251. type  in  a  subtype  indication  are  index  constraints  and discriminant
  5252. constraints.  (See sections 3.6.1 and 3.7.2 for  the  rules  applicable  to
  5253. these  subtype  indications.)   An  access value belongs to a corresponding
  5254. subtype of an access type either if the access value is the null  value  or
  5255. if the value of the designated object satisfies the constraint.
  5256.  
  5257. Examples:
  5258.  
  5259.     type FRAME is access MATRIX;        --  see 3.6
  5260.  
  5261.     type BUFFER_NAME is access BUFFER;  --  see 3.7.1
  5262.  
  5263. Notes:
  5264.  
  5265. An access value delivered by an allocator can be assigned to several access
  5266. objects.   Hence it is possible for an object created by an allocator to be
  5267. designated by more than one variable or constant of the  access  type.   An
  5268. access  value  can  only  designate  an object created by an allocator;  in
  5269. particular,  it  cannot  designate  an  object  declared   by   an   object
  5270. declaration.
  5271.  
  5272. If the type of the objects designated by the access values is an array type
  5273. or a type with discriminants, these objects are constrained with either the
  5274. array  bounds  or the discriminant values supplied implicitly or explicitly
  5275.  
  5276.  
  5277.                                   3 - 79
  5278.  
  5279.  
  5280.  
  5281.  
  5282.  
  5283.  
  5284.  
  5285.  
  5286. for the corresponding allocators (see 4.8).
  5287.  
  5288. Access values are called pointers or references in some other languages.
  5289.  
  5290. References:  allocator 4.8, array type 3.6, assignment  5.2,  belong  to  a
  5291. subtype 3.3, constant 3.2.1, constraint 3.3, discriminant constraint 3.7.2,
  5292. elaboration  3.9,  index constraint 3.6.1, index specification 3.6, limited
  5293. type 7.4.4, literal 4.2, name 4.1, object 3.2.1, object declaration  3.2.1,
  5294. reserved  word 2.9, satisfy 3.3, simple name 4.1, subcomponent 3.3, subtype
  5295. 3.3, subtype indication 3.3.2, type 3.3, variable 3.2.1
  5296.  
  5297.  
  5298.  
  5299.  
  5300.  
  5301.  
  5302.  
  5303.  
  5304.  
  5305.  
  5306.  
  5307.  
  5308.  
  5309.  
  5310.  
  5311.  
  5312.  
  5313.  
  5314.  
  5315.  
  5316.  
  5317.  
  5318.  
  5319.  
  5320.  
  5321.  
  5322.  
  5323.  
  5324.  
  5325.  
  5326.  
  5327.  
  5328.  
  5329.  
  5330.  
  5331.  
  5332.  
  5333.  
  5334.  
  5335.  
  5336.  
  5337.  
  5338.  
  5339.  
  5340.  
  5341.  
  5342.  
  5343.                                   3 - 80
  5344.  
  5345.  
  5346.  
  5347.  
  5348.  
  5349.  
  5350.  
  5351.  
  5352. 3.8.1  Incomplete Type Declarations
  5353.  
  5354.  
  5355. There are no particular limitations on the designated type   of  an  access
  5356. type.  In particular, the type of a component of the designated type can be
  5357. another  access  type, or even the same access type.  This permits mutually
  5358. dependent and recursive access types.  Their declarations require  a  prior
  5359. incomplete (or private) type declaration for one or more types.
  5360.  
  5361.     incomplete_type_declaration ::= type identifier [discriminant_part];
  5362.  
  5363. For  each  incomplete  type  declaration,  there  must  be  a corresponding
  5364. declaration  of  a  type  with  the  same  identifier.   The  corresponding
  5365. declaration  must be either a full type declaration or the declaration of a
  5366. task type.  In the rest of this section, explanations are given in terms of
  5367. full type declarations;  the same rules apply also to declarations of  task
  5368. types.  If the incomplete type declaration occurs immediately within either
  5369. a declarative part or the visible part of a package specification, then the
  5370. full  type  declaration  must  occur  later  and  immediately  within  this
  5371. declarative part or visible  part.   If  the  incomplete  type  declaration
  5372. occurs immediately within the private part of a package, then the full type
  5373. declaration must occur later and immediately within either the private part
  5374. itself, or the declarative part of the corresponding package body.
  5375.  
  5376. A  discriminant part must be given in the full type declaration if and only
  5377. if one is given in the incomplete type declaration;  if discriminant  parts
  5378. are  given,  then  they must conform (see 6.3.1 for the conformance rules).
  5379. Prior to the end of the full type declaration, the only allowed  use  of  a
  5380. name  that  denotes a type declared by an incomplete type declaration is as
  5381. the type mark in the subtype indication of an access type definition;   the
  5382. only   form   of  constraint  allowed  in  this  subtype  indication  is  a
  5383. discriminant constraint.
  5384.  
  5385. The elaboration of an incomplete type declaration creates a type.   If  the
  5386. incomplete  type  declaration  has  a  discriminant  part, this elaboration
  5387. includes that of the discriminant part:  in such a case,  the  discriminant
  5388. part of the full type declaration is not elaborated.
  5389.  
  5390. Example of a recursive type:
  5391.  
  5392.     type CELL;  --  incomplete type declaration
  5393.     type LINK is access CELL;
  5394.  
  5395.     type CELL is
  5396.        record
  5397.           VALUE : INTEGER;
  5398.           SUCC  : LINK;
  5399.           PRED  : LINK;
  5400.        end record;
  5401.  
  5402.     HEAD : LINK := new CELL'(0, null, null);
  5403.     NEXT : LINK := HEAD.SUCC;
  5404.  
  5405. Examples of mutually dependent access types:
  5406.  
  5407.  
  5408.  
  5409.                                   3 - 81
  5410.  
  5411.  
  5412.  
  5413.  
  5414.  
  5415.  
  5416.  
  5417.  
  5418.     type PERSON(SEX : GENDER);  --  incomplete type declaration
  5419.     type CAR;                   --  incomplete type declaration
  5420.  
  5421.     type PERSON_NAME is access PERSON;
  5422.     type CAR_NAME    is access CAR;
  5423.  
  5424.     type CAR is
  5425.        record
  5426.           NUMBER : INTEGER;
  5427.           OWNER  : PERSON_NAME;
  5428.        end record;
  5429.  
  5430.  
  5431.  
  5432.  
  5433.  
  5434.  
  5435.  
  5436.  
  5437.  
  5438.  
  5439.  
  5440.  
  5441.  
  5442.  
  5443.  
  5444.  
  5445.  
  5446.  
  5447.  
  5448.  
  5449.  
  5450.  
  5451.  
  5452.  
  5453.  
  5454.  
  5455.  
  5456.  
  5457.  
  5458.  
  5459.  
  5460.  
  5461.  
  5462.  
  5463.  
  5464.  
  5465.  
  5466.  
  5467.  
  5468.  
  5469.  
  5470.  
  5471.  
  5472.  
  5473.  
  5474.  
  5475.                                   3 - 82
  5476.  
  5477.  
  5478.  
  5479.  
  5480.  
  5481.  
  5482.  
  5483.  
  5484.     type PERSON(SEX : GENDER) is
  5485.        record
  5486.           NAME    : STRING(1 .. 20);
  5487.           BIRTH   : DATE;
  5488.           AGE     : INTEGER range 0 .. 130;
  5489.           VEHICLE : CAR_NAME;
  5490.           case SEX is
  5491.              when M => WIFE    : PERSON_NAME(SEX => F);
  5492.              when F => HUSBAND : PERSON_NAME(SEX => M);
  5493.           end case;
  5494.        end record;
  5495.  
  5496.     MY_CAR, YOUR_CAR, NEXT_CAR : CAR_NAME;  --  implicitly initialized with null value
  5497.  
  5498. References:   access  type  3.8, access type definition 3.8, component 3.3,
  5499. conform 6.3.1, constraint  3.3,  declaration  3.1,  declarative  item  3.9,
  5500. designate  3.8,  discriminant  constraint  3.7.2,  discriminant part 3.7.1,
  5501. elaboration 3.9, identifier 2.3, name 4.1, subtype indication  3.3.2,  type
  5502. 3.3, type mark 3.3.2
  5503.  
  5504.  
  5505.  
  5506. 3.8.2  Operations of Access Types
  5507.  
  5508.  
  5509. The  basic  operations of an access type include the operations involved in
  5510. assignment,   allocators   for   the   access   type,   membership   tests,
  5511. qualification,   explicit   conversion,  and  the  literal  null.   If  the
  5512. designated type is a type with discriminants, the basic operations  include
  5513. the  selection  of the corresponding discriminants;  if the designated type
  5514. is  a  record  type,  they  include  the  selection  of  the  corresponding
  5515. components;   if  the  designated  type  is an array type, they include the
  5516. formation of indexed components and slices;  if the designated  type  is  a
  5517. task   type,   they  include  selection  of  entries  and  entry  families.
  5518. Furthermore, the basic operations  include  the  formation  of  a  selected
  5519. component with the reserved word all (see 4.1.3).
  5520.  
  5521. If  the  designated type is an array type, the basic operations include the
  5522. attributes that have the attribute  designators  FIRST,  LAST,  RANGE,  and
  5523. LENGTH  (likewise,  the  attribute designators of the N-th dimension).  The
  5524. prefix of each of these attributes must be a  value  of  the  access  type.
  5525. These  attributes yield the corresponding characteristics of the designated
  5526. object (see 3.6.2).
  5527.  
  5528. If the designated type is a task type, the  basic  operations  include  the
  5529. attributes that have the attribute designators TERMINATED and CALLABLE (see
  5530. 9.9).  The prefix of each of these attributes must be a value of the access
  5531. type.   These  attributes  yield  the  corresponding characteristics of the
  5532. designated task objects.
  5533.  
  5534. In addition, the  attribute  T'BASE  (see  3.3.3)  and  the  representation
  5535. attributes T'SIZE and T'STORAGE_SIZE (see 13.7.2) are defined for an access
  5536. type  or subtype T;  the attributes A'SIZE and A'ADDRESS are defined for an
  5537. access object A (see 13.7.2).
  5538.  
  5539.  
  5540.  
  5541.                                   3 - 83
  5542.  
  5543.  
  5544.  
  5545.  
  5546.  
  5547.  
  5548.  
  5549.  
  5550. Besides the basic operations, the operations of an access type include  the
  5551. predefined comparison for equality and inequality.
  5552.  
  5553. References:   access  type  3.8,  allocator 4.8, array type 3.6, assignment
  5554. 5.2, attribute 4.1.4, attribute designator  4.1.4,  base  type  3.3,  basic
  5555. operation  3.3.3, collection 3.8, constrained array subtype 3.6, conversion
  5556. 4.6,  designate  3.8,  designated  subtype  3.8,   designated   type   3.8,
  5557. discriminant 3.3, indexed component 4.1.1, literal 4.2, membership test 4.5
  5558. 4.5.2,  object 3.2.1, operation 3.3, private type 7.4, qualified expression
  5559. 4.7, record type 3.7, selected component 4.1.3, slice 4.1.2,  subtype  3.3,
  5560. task type 9.1, type 3.3
  5561.  
  5562.  
  5563.  
  5564.  
  5565.  
  5566.  
  5567.  
  5568.  
  5569.  
  5570.  
  5571.  
  5572.  
  5573.  
  5574.  
  5575.  
  5576.  
  5577.  
  5578.  
  5579.  
  5580.  
  5581.  
  5582.  
  5583.  
  5584.  
  5585.  
  5586.  
  5587.  
  5588.  
  5589.  
  5590.  
  5591.  
  5592.  
  5593.  
  5594.  
  5595.  
  5596.  
  5597.  
  5598.  
  5599.  
  5600.  
  5601.  
  5602.  
  5603.  
  5604.  
  5605.  
  5606.  
  5607.                                   3 - 84
  5608.  
  5609.  
  5610.  
  5611.  
  5612.  
  5613.  
  5614.  
  5615.  
  5616. 3.9  Declarative Parts
  5617.  
  5618.  
  5619. A declarative part contains declarative items (possibly none).
  5620.  
  5621.     declarative_part ::=
  5622.        {basic_declarative_item} {later_declarative_item}
  5623.  
  5624.     basic_declarative_item ::= basic_declaration
  5625.        | representation_clause | use_clause
  5626.  
  5627.     later_declarative_item ::= body
  5628.        | subprogram_declaration | package_declaration
  5629.        | task_declaration       | generic_declaration
  5630.        | use_clause             | generic_instantiation
  5631.  
  5632.     body ::= proper_body | body_stub
  5633.  
  5634.     proper_body ::= subprogram_body | package_body | task_body
  5635.  
  5636. The  elaboration  of  a declarative part consists of the elaboration of the
  5637. declarative items, if any, in the order in which  they  are  given  in  the
  5638. declarative  part.  After its elaboration, a declarative item is said to be
  5639. elaborated.  Prior to the completion of its elaboration  (including  before
  5640. the elaboration), the declarative item is not yet elaborated.
  5641.  
  5642. For  several  forms  of declarative item, the language rules (in particular
  5643. scope and visibility rules) are  such  that  it  is  either  impossible  or
  5644. illegal  to  use  an  entity before the elaboration of the declarative item
  5645. that declares this entity.  For example, it is not possible to use the name
  5646. of a type for an object declaration if the corresponding  type  declaration
  5647. is  not  yet  elaborated.   In the case of bodies, the following checks are
  5648. performed:
  5649.  
  5650.   -  For a subprogram call, a check is made that the body of the subprogram
  5651.      is already elaborated.
  5652.  
  5653.   -  For the activation of a task, a check is made that  the  body  of  the
  5654.      corresponding task unit is already elaborated.
  5655.  
  5656.   -  For the instantiation of a generic unit that has a body,  a  check  is
  5657.      made that this body is already elaborated.
  5658.  
  5659. The exception PROGRAM_ERROR is raised if any of these checks fails.
  5660.  
  5661. If  a subprogram declaration, a package declaration, a task declaration, or
  5662. a generic declaration is a declarative item of a  given  declarative  part,
  5663. then  the  body  (if  there  is  one)  of  the program unit declared by the
  5664. declarative item must itself be a declarative item of this declarative part
  5665. (and must appear later).  If the body is a body  stub,  then  a  separately
  5666. compiled  subunit  containing the corresponding proper body is required for
  5667. the program unit (see 10.2).
  5668.  
  5669. References:  activation 9.3, instantiation  12.3,  program_error  exception
  5670. 11.1, scope 8.2, subprogram call 6.4, type 3.3, visibility 8.3
  5671.  
  5672.  
  5673.                                   3 - 85
  5674.  
  5675.  
  5676.  
  5677.  
  5678.  
  5679.  
  5680.  
  5681.  
  5682. Elaboration  of  declarations:   3.1,  component  declaration 3.7, deferred
  5683. constant  declaration  7.4.3,  discriminant  specification   3.7.1,   entry
  5684. declaration   9.5,   enumeration   literal   specification  3.5.1,  generic
  5685. declaration 12.1, generic instantiation 12.3, incomplete  type  declaration
  5686. 3.8.1,  loop  parameter specification 5.5, number declaration 3.2.2, object
  5687. declaration 3.2.1, package declaration 7.2,  parameter  specification  6.1,
  5688. private  type  declaration  7.4.1,  renaming  declaration  8.5,  subprogram
  5689. declaration 6.1, subtype declaration  3.3.2,  task  declaration  9.1,  type
  5690. declaration 3.3.1
  5691.  
  5692.  
  5693.  
  5694.  
  5695.  
  5696.  
  5697.  
  5698.  
  5699.  
  5700.  
  5701.  
  5702.  
  5703.  
  5704.  
  5705.  
  5706.  
  5707.  
  5708.  
  5709.  
  5710.  
  5711.  
  5712.  
  5713.  
  5714.  
  5715.  
  5716.  
  5717.  
  5718.  
  5719.  
  5720.  
  5721.  
  5722.  
  5723.  
  5724.  
  5725.  
  5726.  
  5727.  
  5728.  
  5729.  
  5730.  
  5731.  
  5732.  
  5733.  
  5734.  
  5735.  
  5736.  
  5737.  
  5738.  
  5739.                                   3 - 86
  5740.  
  5741.  
  5742.  
  5743.  
  5744.  
  5745.  
  5746.  
  5747.  
  5748. Elaboration  of type definitions:  3.3.1, access type definition 3.8, array
  5749. type  definition  3.6,  derived  type  definition  3.4,  enumeration   type
  5750. definition  3.5.1,  integer  type  definition  3.5.4,  real type definition
  5751. 3.5.6, record type definition 3.7
  5752.  
  5753. Elaboration of other constructs:  context  clause  10.1,  body  stub  10.2,
  5754. compilation  unit 10.1, discriminant part 3.7.1, generic body 12.2, generic
  5755. formal  parameter  12.1  12.3,  library  unit  10.5,  package   body   7.1,
  5756. representation  clause  13.1,  subprogram body 6.3, subunit 10.2, task body
  5757. 9.1, task object 9.2, task specification 9.1, use clause 8.4,  with  clause
  5758. 10.1.1
  5759.  
  5760.  
  5761.  
  5762.  
  5763.  
  5764.  
  5765.  
  5766.  
  5767.  
  5768.  
  5769.  
  5770.  
  5771.  
  5772.  
  5773.  
  5774.  
  5775.  
  5776.  
  5777.  
  5778.  
  5779.  
  5780.  
  5781.  
  5782.  
  5783.  
  5784.  
  5785.  
  5786.  
  5787.  
  5788.  
  5789.  
  5790.  
  5791.  
  5792.  
  5793.  
  5794.  
  5795.  
  5796.  
  5797.  
  5798.  
  5799.  
  5800.  
  5801.  
  5802.  
  5803.  
  5804.  
  5805.                                   3 - 87
  5806.  
  5807.  
  5808.  
  5809.  
  5810.